Problem: I would like to require the User to select at least one checkbox from a checkboxes group in a CRED form.
Solution: There's no way to do this from wp-admin, but you can apply backend validation using the cred_form_validate hook that will require at least one checkbox.
add_filter('cred_form_validate','cred_form_validation', 2, 10); function cred_form_validation( $field_data, $form_data ) { // field data are field values and errors list($fields,$errors)=$field_data; $forms = array( 1234 ); // check to see if this is the correct form if ( in_array( $form_data['id'], $forms ) ) { if ( !isset($fields['wpcf-checkboxes']['value'][0])) $errors['checkboxes'] = 'At least one checkbox is required'; } return array( $fields, $errors ); }
Change 1234 to match the CRED form ID, and change 'checkboxes' in both places to match the field slug.
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)
Ce sujet contient 3 réponses, a 2 voix.
Dernière mise à jour par Il y a 6 années et 8 mois.
Assisté par: Christian Cox.