Is there any way to insert into optional fields?
Is there any way to insert into optional fields?
I have a working editor and now I have added some fields that I needed for what the database interfaces with namely the end user application.
My application needed some additional fields such as "DoesImage1Exist", "DoesImage2Exist", etc. This was needed to find out if the user has used the datatables editor to upload any image files. Right now I am doing this manually within my database by going to these new optional fields to toggle them on/off. What I am wondering if there is a way for my custom editor.php file to automate this? Hopefully, this question is making sense.
Maybe a screenshot can better help to illustrate what I what mean? As you can see from my screenshot that should a user decide not to upload a picture when they click the "Create" button what I want to happen is in the same table that attributes about this form reside in there are those fields I mentioned before all I want is for them to toggle appropriately. For Example, should the user not upload a "Profile Picture" I want the field "DoesProfilePicExist" to be "0" which means no.
I don't know how to do this on the server side code. How can I check to see if the a picture has been uploaded and if so, to update a field accordingly?
Any advice how I can achieve this? As I mentioned before I am doing this manually after every upload.
Thank you!
Answers
Hi,
Sounds like a good use case for server-side events. e.g.:
To be honest, I'd be tempted just to check if
Image1
isnull
or not rather than storing that information in another column - but if that's what the app is already expected, a server-side event is the way to do it.Allan
Allan,
This is how I attempted it. Not sure if this the correct answer, but I meant to post this sooner, but I got pulled in 23432 different directions. Ha ha.
https://editor.datatables.net/reference/event/preSubmit
I used the preSubmit event to check to see within the editor if any of those images have been uploaded like so...
One more thing I need to mention about client side code is that I made these within the editor as visibility: false; The end user doesn't really need to interact with them as they are only used in another application. That's the reason why I can modify those fields because they are hidden and shouldn't be touched by the user.
Further on the on the server side code I added the fields...
This way the editor is now aware of these extra fields I added.
What do you think of this solution Allan? Am I checking correctly to see if the images are upload correctly? Or do you think doing it server side is the best way?
I think that looks good to me if you need those column values to be set in the database. As I say, I'd be tempted just to check
Image1
, etc, and see if they have a value or arenull
, but if you need them, then that's a good way of doing it.Allan