Forums

[Problem] Chronoconnectivity edit an upload file

rushseeker 28 Apr, 2011
Hi
I have a form that have a lot of text field, checkbox and a file field. like this:
	<input class="cf_fileinput cf_inputbox" title="" size="20" id="file_0" name="file_0" type="file" />


When i use chronoform and upload a file that's ok!

The problem is, when go to edit: suppose that there is a file. if the field file_0 is empty and i click submit, the link to the file previously uploaded is lost because chronoconnectivity insert a NOFILE value in file_0.
I need that: if there is a previously uploaded file and i don't edit field file_0 the file stay in the server.
If i'll change file_0, then upload another file, then i'll delete the old file and upload the new file.

Sorry for Bad English.
GreyHead 05 May, 2011
Hi rushseeker,

I think that this may solve that problem.

In the Form OnSubmit Before Email box add this code snippet:
<?php
$file_0 = JRequest::getString('file_0', '', 'post');
if ( !$file_0 ) {
  unset($_POST['file_0']);
}
?>
This should make sure that the empty value isn't saved to the database table.

Bob
rushseeker 08 May, 2011
thank you for your answer.

this solution don't work.
menchee 08 May, 2011
Worked for me (version 3.2).

Just make sure you didn't copy Bob's typo of the curly bracket instead of the square one after the POST key:
[code]unset($_POST['file_0'});[/code]
Should be
unset($_POST['file_0']);


Emanuel.
GreyHead 08 May, 2011
Hi menchee & rushseeker,

Sorry about the typo, I corrected my earlier post.

Bob
megana 06 Feb, 2013
Hi all,

I'm trying to do this as well but the posted code snippet is not helping. My upload field is called 'photo' so I replaced 'file_0' with 'photo' everywhere in the code, but that didn't help either.

Maybe I put it in the wrong place...I didn't see "OnSubmit Before Email" so I put a Custom Code box in between "Upload Files" and "DB Save" in my events.

Any tips? I have the latest versions (as of today) of CF and CC for Joomla 2.5.
Max_admin 07 Feb, 2013
Hi Megana,

Best way to do this is to load the ex-file name into a hidden field BEFORE the upload file, and disable the "upload file ghost" if you have it enabled (under the file field settings), that should keep the latest uploaded file name.

If you want to do it the same way here then you can use this code instead:


<?php
if(empty($form->data['file_field_name'])){
unset($form->data['file_field_name']);
}
?>


That code should go in a custom code action AFTER the "Upload files" action.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
megana 07 Feb, 2013
Thanks Max! Working great now!
This topic is locked and no more replies can be posted.