Problem: I would like to make the post parent field and featured image field required in my CRED form.
Solution: The parent post CRED field shortcode will accept a required='true' attribute like this:
[cred_field field='_wpcf_belongs_slug_id' value='' select_text='--- not set ---' class='form-control' output='bootstrap' required='true']
The featured image shortcode will not accept a required='true' attribute, so the only way to require a featured image is to use custom code. The CRED API cred_form_validate can be used to make the featured image required. Add this code to your child theme's functions.php file:
add_filter( 'cred_form_validate', 'require_featured_image_validation', 10, 2 ); function require_featured_image_validation( $data, $form_data ) { $forms = array( 1234, 5678 ); if( in_array( $form_data['id'], $forms ) ){ list($fields,$errors)=$data; if (empty($fields['_featured_image']['value'])) { $errors['_featured_image'] = __( 'Featured image is required', 'your-language-domain'); } $data =array($fields,$errors); } return $data; }
Replace 1234, 5678 with a comma-separated list of any CRED form IDs where you want to make the featured image required.
Relevant Documentation: https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate
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 |
---|---|---|---|---|---|---|
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 6 years, 8 months ago.
Assisted by: Christian Cox.