Skip Navigation

[Resolved] Make WP Featured image required on multiple CRED forms

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

Problem: I would like to make the featured image field required on multiple CRED forms.

Solution:

function my_cred_featured_image_validation($field_data, $form_data) {
    list($fields,$errors)=$field_data;
    $form_ids = [123,456];
    if (in_array($form_data['id'], $form_ids)) {
 
        if ( empty($fields['_featured_image']['value']) ) {
            $errors['_featured_image']='This field is required';
        }
    }
 
    return array($fields,$errors);
}
add_filter('cred_form_validate', 'my_cred_featured_image_validation', 10, 2);

Change 123,456 to a comma-separated list of form IDs.

Relevant Documentation: https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

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

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by arnoldd 6 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#577632

For multiple CRED forms i need that the WP featured image is requires. Is this code still the right solution: https://toolset.com/forums/topic/cred-make-featured-image-field-required/

If so, how do I apply this to multiple forms instead of one?

#577690

Hi, yes the code, with Adriano's recommended change, is still correct. In order to apply it to more than one form, you can use this modified version:

function my_cred_featured_image_validation($field_data, $form_data) {
    list($fields,$errors)=$field_data;
    $form_ids = [123,456];
    if (in_array($form_data['id'], $form_ids)) {

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

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

Replace 123,456 with a comma-separated list of numeric CRED form IDs.

#577701

Again, super! Thanks.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.