Hi
I'm trying to make my taoxonomies and post content description required in my post form using this snippet, but it isn't working. Correct post form ID and slugs are in use:
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']==107166) {
// check at least one of required taxonomies set
if ( empty( $fields['cv-arbejdstid']['value'] ) && empty( $fields['cv-arbejdsvilkar']['value'] ) && empty( $fields['cv-aktiv-jobsogende']['value'] ) && empty( $fields['cv-foretrukken-branche']['value'] ) ) {
$errors['cv-arbejdstid'] = 'You must choose at least one sector';
}
}
return array($fields,$errors);
}
add_filter( 'cred_form_validate', 'tssupp_require_sector', 10, 2 );
Regards
Hi,
Thank you for contacting us and I'd be happy to assist.
To troubleshoot this, I'll need to see exactly how this form and the taxonomies are set up in the admin area.
Can you please share temporary admin login details, along with the link to the page, where this form can be seen?
Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.
regards,
Waqar
Thank you for sharing the access details.
I couldn't find the custom code snippet for the form validation, anywhere on the website, so it seems like it has been removed.
You can use the slightly updated code, that handles the validation for each of those 4 taxonomies and the post content, separately:
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']==107166 ) {
// check at least one of required taxonomies set: cv-arbejdstid
if ( empty($fields['cv-arbejdstid']['value']) ) {
$errors['cv-arbejdstid'] = 'You must choose at least one sector';
}
// check at least one of required taxonomies set: cv-arbejdsvilkar
if ( empty($fields['cv-arbejdsvilkar']['value']) ) {
$errors['cv-arbejdsvilkar'] = 'You must choose at least one sector';
}
// check at least one of required taxonomies set: cv-aktiv-jobsogende
if ( empty($fields['cv-aktiv-jobsogende']['value']) ) {
$errors['cv-aktiv-jobsogende'] = 'You must choose at least one sector';
}
// check at least one of required taxonomies set: cv-foretrukken-branche
if ( empty($fields['cv-foretrukken-branche']['value']) ) {
$errors['cv-foretrukken-branche'] = 'You must choose at least one sector';
}
// check that some post content is set: post_content
if ( empty($fields['post_content']['value']) ) {
$errors['post_content'] = 'Content cannot be empty';
}
}
return array($fields,$errors);
}
add_filter( 'cred_form_validate', 'tssupp_require_sector', 10, 2 );
Feel free to change the validation messages for each field, as needed.
My issue is resolved now. Thank you!