I have followed the guidance in the code from here - https://toolset.com/forums/topic/cant-validate-checkboxes/
But, the checkbox is still not mandatory on this form - w.showprowess.com/expert-application/
Can someone please guide me on what I am missing?
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
function expert_mandatory_fields_check($field_data, $form_data) {
// Split $field_data into separate $fields and $errors
list( $fields,$errors ) = $field_data;
$forms = array( 11422 );
// check to see if this is the correct form
if ( in_array( $form_data['id'], $forms ) ) {
if ( !isset($fields['wpcf-expert-self-reported-skills']['value'][0]))
$errors['checkboxes'] = 'Please select at least one skill you can evaluate';
}
return array($fields,$errors);
}
add_filter( 'cred_form_validate', 'expert_mandatory_fields_check', 10, 2 );
Hello and thank you for contacting Toolset support.
The code seems correct to me. It will need some debugging to spot the issue. Can I log in to your website and check it further? Your next reply will be private to let you share credentials safely. I'll need FTP access too. ** Make a database backup before sharing credentials. **
If I needed to debug further, I'll have to work on a copy of your website on my local development environment. Let me know if that's fine with you.
I confirm that the credentials are working for me. However, I could not find the code snippet. Can you tell where the code is being added?
Jamal,
My bad. The code snippet is in the toolset custom code tab.
Name: make-expert-fields-mandatory
hidden link
Also, I am seeing the following error on page load. Not sure if it is related - Uncaught ReferenceError: wptCondCustomTriggers is not defined
at (index):973
The issue within the code is on line 22. The code should be:
$errors['expert-self-reported-skills'] = 'Please select at least one skill you can evaluate';
Instead of:
$errors['checkboxes'] = 'Please select at least one skill you can evaluate';
We need to use the field's slug as the key in the errors array.
Regarding the new error that you encounter, please open a new ticket and let us know what steps we should follow to see the error, and we'll do our best to help.
Thank you, Jamal. I appreciate the support!
My issue is resolved now. Thank you!