Skip Navigation

[Closed] I want to require a feature image be uploaded

This support ticket is created 7 years, 6 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

This topic contains 4 replies, has 2 voices.

Last updated by Konstantinos Galanakis 7 years, 6 months ago.

Assisted by: Konstantinos Galanakis.

Author
Posts
#446094

I am trying to require that a feature image be uploaded in one of my forms

I used the code suggested in this post.. https://toolset.com/forums/topic/cred-make-featured-image-field-required/ revised as suggested by Adriano.... Referring to my CRED form...

As follows:
function my_cred_validation($field_data, $form_data) {
list($fields,$errors)=$field_data;

if ($form_data['id'] == 1564) {

if ( empty($fields['_featured_image']['value']) ) {
$errors['_featured_image']='This field is required';
}
}

return array($fields,$errors);
}
add_filter('cred_form_validate', 'my_cred_validation', 10, 2);

It worked to the extent that it prevented saving the post without uploading a featured image.... I got the error “The post was not saved because of the following problem:
Featured Image: This field is required”

So I tested again, this time uploading an image (which seemed to work fine). However it wouldn’t save .... the same error message was returned.

Any ideas how to fix this?

Cheers

Peter

#446244

Hello Adam.

Thank you for contacting the Toolset Support.

It seems that you use outdated versions of many Toolset Family plugins. Please update your plugins and then try Adriano's solution once again to see if the issue is resolved.

I've tried that solution to a local WordPress installation and it worked like a charm.

If you don't get your issue resolved or if you have any further issues, please let me know.

Regards

#447272

Konstantinos

I have upgraded all plugins and still have the same problem... The form does not recognise that a featured image has been uploaded when one has.

The image uploads... is visible in Media (in the WP Backend) but I still cannot submit my form ... it gives me the error:

“The post was not saved because of the following problem:
Featured Image: This field is required”

any ideas?

Peter

#447273

Konstantinos

I just remembered that I got a solution to a problem from Nigel ... the featured image was not sticking to announcements... which he fixed by providing the following custom code:

/**
* Custom code to force add thumbnail meta
* to add announcement CRED form post
*/
function force_thumbnail( $post_id, $form_data ) {

if ( $form_data['id'] == 1564 && !empty( $_POST['_featured_image'] ) ) {

$args = array(
'numberposts' => 1,
'post_type' => 'attachment',
'post_parent' => $post_id
);
$thumb = get_posts( $args );

$meta_update = add_post_meta( $post_id, "_thumbnail_id", $thumb[0]->ID, true );

}
}
add_action( 'cred_submit_complete', 'force_thumbnail', 10, 2 );

This was addressed in my support request as follows: https://toolset.com/forums/topic/i-cannot-get-featured-image-in-cred-form-to-save-against-post/

I wonder if the code snippets are clashing?

#447303

Hello Peter.

These two codes you are providing above, do not conflict with each other. The work well together on my local WordPress installation.

Actually, the code provided by Daniel can be safely removed as it was a hotfix to an issue that was resolved in the latest version of the plugin.

In order, to further help you resolve this issue, I would need to request temporary access (WP-Admin and FTP) to your site, or preferably to a test site where the problem has been replicated if possible, and check if some configurations might need to be changed.

Your next answer will be private which means only you and I have access to it.

*** Please backup your database and website! ***

If you have any further issues, please let me know.

Regards

The topic ‘[Closed] I want to require a feature image be uploaded’ is closed to new replies.