Problem: I would like to require at least one taxonomy term is selected in a Form.
Solution: Use the cred_form_validate API to check the Form submission to confirm at least one term is selected.
add_filter('cred_form_validate','term_checkboxes_form_validation', 10, 2); function term_checkboxes_form_validation( $field_data, $form_data ) { $tax = 'YOUR-TAXONOMY-SLUG'; $forms = array( 12345 ); $msg = 'At least one term is required.'; // you should not edit below this line // field data are field values and errors list($fields,$errors)=$field_data; // validate if correct CRED form ID if ( in_array( $form_data['id'], $forms ) ) { if ( !isset($fields[$tax]['value']) || $fields[$tax]['value']=='') $errors[$tax] = $msg; } return array( $fields, $errors ); }
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/
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 7 replies, has 2 voices.
Last updated by 5 years ago.
Assisted by: Christian Cox.