Problem: I would like to require Users to upload an image and select at least one taxonomy term in my Form.
Solution: You can make a custom field image required by editing the custom field in Toolset > Custom fields > Post fields. You can use a custom code snippet with the Forms API to validate at least one term checkbox is checked:
<?php /** * New custom code snippet. */ toolset_snippet_security_check() or die( 'Direct access is not allowed' ); add_filter('cred_form_validate','term_checkboxes_form_validation', 10, 2); function term_checkboxes_form_validation( $field_data, $form_data ) { $tax = 'app-name'; $forms = array( 15 ); $msg = 'At least one checkbox 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'][0])) $errors[$tax] = $msg; } return array( $fields, $errors ); }
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, 9 months ago.
Assisted by: Christian Cox.