Tell us what you are trying to do?
I'd like t make all taxonomy fields on front end forms not only required but also have a zero / "please select" value to begin with. If the user does not select a value then they are presented with a "This value is required" error. Currently all I can see is that the taxonomy fields are not required and have the first available value selected. This allows the user to submit the form with an incorrect value selected.
See attached image - Job Title is not required after submitting the form after submitting without other required fields filled in.
Is there any documentation that you are following?
The tutorials.
What is the link to your site?
hidden link
Hello,
Given that making a taxonomy required isn't something that is possible with wordpress by default, you can use Form filter hook "cred_form_validate" to add the custom validation, for example:
Toolset->Settings->Custom Code, create and activate one item, with below codes:
function tssupp_require_category($field_data, $form_data) {
// Split $field_data into separate $fields and $errors
list( $fields,$errors ) = $field_data;
// validate specific form
$form_id = 12345; // specific post form ID
$taxonomy_slug = 'my-tax-slug'; // specific taxonomy slug
if ( $form_data['id'] == $form_id ) {
// check at least one of required taxonomies set
if ( empty( $fields[$taxonomy_slug]['value'] ) ) {
$errors[$taxonomy_slug] = 'You must choose at least one term';
}
}
return array($fields,$errors);
}
add_filter( 'cred_form_validate', 'tssupp_require_category', 10, 2 );
Please replace 12345 with your post form ID
replace my-tax-slug with your custom taxonomy slug
More help:
https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate