Problem: I would like to set up some custom validation for a post Form. I would like to require at least one term from a custom taxonomy.
Solution: Use the cred_form_validate API to test the value of the taxonomy field, and return an error if none is selected.
function tssupp_require_sector($field_data, $form_data) { // Split $field_data into separate $fields and $errors list( $fields,$errors ) = $field_data; // validate specific form if ( $form_data['id']==2454) { // check at least one of required taxonomies set if ( empty( $fields['p-carer-time']['value'] ) ) { $errors['p-carer-time'] = 'You must choose at least one sector'; } } return array($fields,$errors); } add_filter( 'cred_form_validate', 'tssupp_require_sector', 10, 2 );
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 5 replies, has 2 voices.
Last updated by 5 years, 5 months ago.
Assisted by: Christian Cox.