ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

File upload in edit form

cmwincom 11 Feb, 2017
Trying to make sense of a FAQ, https://www.chronoengine.com/faqs/72-ccv5/5238-how-to-use-file-uploads-in-my-edit-form.html, to make it work in my application.

I'm utilizing CC5 and CF5. I have a connection named schools with a model named sdata. In my list actions edit is linked to the form 518schools-edit. In the form is a file upload field named logo. I need to be able to use the file upload field to add or update a logo image and save the file name to the logo field.

In the form in the on submit section I have a File Upload event (which works) followed a Connection Action configured per the FAQ's. It updates all the other fields, but the logo field doesn't update.

Per your FAQ, mentioned above, I tried renaming the field as sdata[logo] and sdata:logo.

I'm not clear on where to do the following because I'm not finding the "Array fields" box.:

"Then you will need to write "Model" in the "Arrays fields" box in order to handle all the file fields under the Model key."

I've also tried to figure out the alternative method mentioned in the FAQ:
Another solution would be to remove the Model name from the file field (e.g: field1) and use that in the file uploads action settings, but then you will have to move the value of the field under the Model key in the data array using PHP:

I'm not sure where to place the following: $form->data["sdata"]["logo"] = $form->data["logo"];

Any help is appreciated.
Max_admin 12 Feb, 2017
Hi cmwincom,

Could you please try v6 of Connectivity ? it has a build in file upload function.

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
cmwincom 12 Feb, 2017
I could do that and I have installed CC6, but since CC6 has an entirely different look and feel I don't really want to take the time to learn it.

All I'm asking for is a bit more detail on your FAQ so that I can implement a solution.
Max_admin 12 Feb, 2017
Hi,

Ok, please try the alternative method you noted and put the code (after changing it to match your model and fields names) inside a "custom code" action before the "Connection action" where you save the data.

Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
cmwincom 12 Feb, 2017
That worked.

My code is:

<?php
$form->data["sdata"]["logo"] = $form->data["logo"];
?>

Now what I need is some code that when editing the record keeps the existing value if there is no change and updates the record if a new file is uploaded.

Current Value Field Value Updated Value
empty empty empty
image1 empty image1
image1 image2 image2

I've used the following code from another post:

<?php
$files_array = array(
'logo'
};
foreach ( $files_array as $v ) {
if ( !$form->data[$v] ) {
unset($form->data[$v]);
}
}
?>

The result is that it is preventing the overwriting of the existing value if the form field is blank, which is what I want. However it also prevents the updating from image1 to image2.

In summary I need to update the value if the file upload field has a new non blank value and does not update if the file upload field is blank.
Max_admin 13 Feb, 2017
Answer
This line:
$form->data["sdata"]["logo"] = $form->data["logo"];
please try to replace with:
if(!empty($form->data["logo"])){
$form->data["sdata"]["logo"] = $form->data["logo"];
}
Best regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
cmwincom 13 Feb, 2017
That did it. Thank you very much.
amheng5 15 Feb, 2019
I'm using cc6 and created an edit form to edit exiting records created in cf6. No problem, except the upload field (upload photo). I want to either replace the single file or upload a file one does not exist for an existing record. The issue is when I I use the file upload field in CC6, it creates a new record rather than replace or add a photo to an exisitng record. screen shot attached. Trying to figure out where I'm going wrong. ThanksCapture.JPG
healyhatman 16 Feb, 2019
Make sure you're sending the form data AND AN ID (or some other way of identifying the record you're updating) along with the form data when you're submitting. And make sure the save data action you're using to update the record is set to update, not auto detect.
amheng5 16 Feb, 2019
Wahoo! It worked. Added the model.file name to the upload field. thank you.
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com