Skip Navigation

[Resolved] Featured image doesn’t upload after failed validation

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that when the user submits a Toolset form with an image field and the form validation causes the form to fail, the images that were in the upload fields are lost.

Solution:

This is actually a known issue that was reported recently for fixing. The issue is because the image is uploaded after the form is submitted. Once the form fails to submit then the image will need to be re-uploaded.

The form is essentially reloaded and since the files weren't uploaded they will need to re-added to the form. Our development team is working on a notice feedback on the form so that user's will know that they need to re-upload the images.

I'm not seeing a fixed version number on our internal escalated ticket for this issue. However the fix will be made available in a future release.

0% of people find this useful.

This support ticket is created 3 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Purchasing WCER 3 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#1978395

I am trying to: Have users submit a post form with a featured image. The form also has validation on it. If the validation passes the image is saved to the post. If the validation fails the image is not saved even after errors are fixed and the form is successfully submitted. The user submission form continues to show that the file is attached even when validation fails.

Looked at this: https://toolset.com/forums/topic/image-upload-issues-after-custom-validation-errors/ however our users are not required to log in to submit the form and checking " Use the WordPress Media Library manager for image, video, audio, or file fields" does not change the outcome (the image still doesn't upload if and validation errors are thrown in the submission process).

Link to a page where the issue can be seen: hidden link

I would like the image to upload even if validation initially fails. If that cannot happen, the less ideal user experience would be to remove the uploaded file so users know they have to reattach it.

Validation code:
add_filter('cred_form_validate','my_validation',10,2);
function my_validation($error_fields, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$error_fields;
//uncomment this if you want to print the field values
//print_r($fields);
//validate if specific form
if ($form_data['id']==4732)
{
//check submitter-name not empty
if (empty($fields['wpcf-submitter-name']['value']))
{
$errors['wpcf-submitter-name']='Required';
}
//check submitter-email not empty
if (empty($fields['wpcf-submitter-email']['value']))
{
$errors['wpcf-submitter-email']='Required';
}
//check if featured image exists
if (empty($fields['_featured_image']['value']))
{
$errors['_featured_image'] = 'Required';
}
//check poster abstract not empty
if (empty($fields['wpcf-poster-abstract']['value'])) {
$errors['wpcf-poster-abstract'] = 'Required';
}
// check at least one of Research Area taxonomy is set
if ( empty( $fields['research-area']['value'])
) {

$errors['research-area'] = 'Sectors the Research Addresses is Required';
}
// check at least one of Primary Topic taxonomy is set
// if ( empty( $fields['poster-topic']['value'])
// ) {
//
// $errors['poster-topic'] = 'Primary Topic of Poster is Required';
// }
}
//return result
return array($fields,$errors);
}

#1978527

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Dung,

Thank you for getting in touch.

This is actually a known issue that was reported recently for fixing. The issue is because the image is uploaded after the form is submitted. Once the form fails to submit then the image will need to be re-uploaded.

The form is essentially reloaded and since the files weren't uploaded they will need to re-added to the form. Our development team is working on a notice feedback on the form so that user's will know that they need to re-upload the images.

I'm not seeing a fixed version number on our internal escalated ticket for this issue. However the fix will be made available in a future release.

Thanks,
Shane

#1978627

Hi Shane,

Thank you for the quick response. Is there and ETA on when this will be fixed? I need to wrap this project up and don't want to have to redo it in another Plugin. Is there a way to remove the image/force the user to re-add it if validation fails ... until the fix is rolled out?

#1978673

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Dung,

Unfortunately there isn't an ETA for this.

Secondly the only workaround at the moment is to add a notice in your failure messages to let the user know that they should re-add their featured image.

Add your featured image message to each of your validation statements, please let me know if this helps.

Thanks,
Shane

#1978755

My issue is resolved now. Thank you!