Forums

updating an image

jmahun 07 Aug, 2015
I cannot figure out how to work with image uploads. I tried following the FAQ at https://www.chronoengine.com/faqs/60-cfv4/cfv4-working-with-the-database/2666-how-can-i-edit-the-record-for-an-%3Cspan%20class= but couldn't get it to work.

I have an input form (Form1) on which the user may include an image in a file upload event. I understand that the image name, with a date prefix, is stored in my table and that the image itself is stored in the components/com_chronoforms5/chronoforms/uploads/Form1/ folder. That part works fine.

I have a second form (Form2) with which the user can edit his record. It includes a file upload event which is meant to allow the user to upload a different image to replace the existing one. While I can load a thumbnail of the existing image as a preview, I can't figure out now to allow the user to upload a replacement image, delete an image, or not overwrite the image with a blank entry if nothing is included in the file upload field.

The FAQ says to enable the Ghost box in the File Upload - I did that and a blank image entry still overwrites the existing image name.
I also don't understand how to "Add a 'delete_checkbox' element..." How do I set that up? Is that just a checkbox with additional code?

Can anyone tell me how to accomplish this?

JM
GreyHead 11 Aug, 2015
Hi JM,

Starting at the end, the 'delete checkbox' is just a plain Checkbox element. In the On Submit event you will use Custom PHP to check if this is set, and if it is, delete the existing saved image and update the database record to match.

The Ghost setting looks different in CFv5 - I'm not sure if you can dynamically set the value and I don't have a convenient table to test with right now. I would probably use Custom PHP again after the Files Upload action in the On Submit event and Unset the value of the file input if it is empty. This should have the same result of stopping the existing file name being over-written.

Bob
jmahun 11 Aug, 2015
Thanks for the information. I'll try your suggestions.
Jerry
jmahun 23 Aug, 2015
Answer
Following you suggestion I used a checkbox field (del_imag) with a single choice (delete=Delete?) for the user to indicate if the image (logo) should be deleted. I included Custom Code with the following php code:
if ($form->data['del_img']=='delete') {
$form->data['logo']='';
}

That worked great.

As far as the Ghost setting, I just ignored that attribute since I couldn't find enough info about v5's implementation of it. It took some experimentation to figure out the correct upload path (a lot of this stuff isn't intuitive) but I eventually got it so a new image is uploaded to the correct original folder.
This topic is locked and no more replies can be posted.