This has really got me stumped.
I have a form that uploades 4 images - named 'logo', and 'gallery1' to 3. The user needs to be able to edit these.
I can get it to upload all images.
I can get it to display these on the form when editing the record, so they can see what was previously uploaded.
I used this code in a Custom Server Side Validation to validate 'logo' and it worked. Uploading new files and not trashing a file if no new file specified.
But using the same code in another Custom Server Side Validation action for the next field 'image1' and it never works. Always evaluates False.
So in trying to understand I removed all actions and started again, but now the same code for the 'logo' field fails to work and I can't get anything to work.
I am stumped totally. After ages searching the forum I can't find any post to really help.
Is there a better way to do this?
I have a form that uploades 4 images - named 'logo', and 'gallery1' to 3. The user needs to be able to edit these.
I can get it to upload all images.
I can get it to display these on the form when editing the record, so they can see what was previously uploaded.
I used this code in a Custom Server Side Validation to validate 'logo' and it worked. Uploading new files and not trashing a file if no new file specified.
<?php
if ($form->data['logo'] != "") {
return true;
} else {
return false;
}
?>
But using the same code in another Custom Server Side Validation action for the next field 'image1' and it never works. Always evaluates False.
So in trying to understand I removed all actions and started again, but now the same code for the 'logo' field fails to work and I can't get anything to work.
I am stumped totally. After ages searching the forum I can't find any post to really help.
Is there a better way to do this?
Hi JeffP,
Please see this FAQ for a way to set up multiple Custom Serverside Validations in the same action.
Bob
Please see this FAQ for a way to set up multiple Custom Serverside Validations in the same action.
Bob
Hi Bob
Had a read of that page. I do need to say that none of these images is required, and I don't want to stop processing if there is no image selected.
Maybe I am wrong, but I don't think I can test all image fields in one Custom Server Side Validation action. Doesn't each field need to be tested in turn and then the Upload Files action performed?
That means 4 Custom Server Side Validation actions, one for each field, to see if a new file has been specified. Then a separate Upload Files action in the On Success section for each Custom Server Side Validation action.
Is that correct?
Had a read of that page. I do need to say that none of these images is required, and I don't want to stop processing if there is no image selected.
Maybe I am wrong, but I don't think I can test all image fields in one Custom Server Side Validation action. Doesn't each field need to be tested in turn and then the Upload Files action performed?
That means 4 Custom Server Side Validation actions, one for each field, to see if a new file has been specified. Then a separate Upload Files action in the On Success section for each Custom Server Side Validation action.
Is that correct?
Hi JeffP,
There is no entry for a file upload input in the $form->data array until after the Upload Files action runs so I don't think that a normal Serverside Validation action will do what you need.
Instead please try adding a Custom Code action after the Upload Files action and before the DB Save action and add this code to it replacing the array values with the names of the file inputs in your form.
Bob
PS It isn't useful to redisplay the value of file inputs in an edit form as there is no way of knowing the path to the file on the user's computer and so the value is incomplete. Because of this most browsers won't allow it.
There is no entry for a file upload input in the $form->data array until after the Upload Files action runs so I don't think that a normal Serverside Validation action will do what you need.
Instead please try adding a Custom Code action after the Upload Files action and before the DB Save action and add this code to it replacing the array values with the names of the file inputs in your form.
<?php
$files_array = array(
'file_upload_1',
'file_upload_2',
'file_upload_3',
'file_upload_4'
};
foreach ( $files_array as $v ) {
if ( !$form->data[$v] ) {
unset($form->data[$v]);
}
}
?>
This should remove any empty file-upload inputs completely from the $form->data array and therefore leave any existing values in the database unchanged.Bob
PS It isn't useful to redisplay the value of file inputs in an edit form as there is no way of knowing the path to the file on the user's computer and so the value is incomplete. Because of this most browsers won't allow it.
This topic is locked and no more replies can be posted.