Skip Navigation

[Resolved] Toolset Form Validation

This support ticket is created 4 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by garenM 4 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#1496167

hey,

im trying to make the checkboxes field required but is not working. Im using the below code. Can you advise please

add_filter('cred_form_validate','cred_form_validation', 2, 10);
function cred_form_validation( $field_data, $form_data ) {
// field data are field values and errors
list($fields,$errors)=$field_data;
$forms = array( 211 );
// check to see if this is the correct form
if ( in_array( $form_data['id'], $forms ) ) {

if ( !isset($fields['wpcf-your-company-s-adherence-to']['value'][0]))
$errors['your-company-s-adherence-to'] = 'At least one checkbox is required';
}

return array( $fields, $errors );
}

#1496259

I have try the below as well

add_filter('cred_form_validate','my_validation',10,2);
function my_validation( $field_data, $form_data ) {
// field data are field values and errors
list($fields,$errors)=$field_data;
$forms = array( 211 );
// check to see if this is the correct form
if ( in_array( $form_data['id'], $forms ) ) {

if ( empty($fields['wpcf-your-company-s-adherence-to']['value']))
$errors['wpcf-your-company-s-adherence-to'] = 'At least one checkbox is required';
}

return array( $fields, $errors );
}

#1496577

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Garen,

Thank you for getting in touch.

Could you test the validation to see if the section of code get run.


add_filter('cred_form_validate','my_validation',10,2);
function my_validation( $field_data, $form_data ) {
// field data are field values and errors
list($fields,$errors)=$field_data;
$forms = array( 211 );
// check to see if this is the correct form
if ( in_array( $form_data['id'], $forms ) ) {

if ( empty($fields['wpcf-your-company-s-adherence-to']['value']))
die('Empty');

}

return array( $fields, $errors );
}

Could you let me know if after you submit the form you see a Page with only "Empty" written on it ?

Thanks,
Shane

#1497505
Untitled-2.jpg

Thank you for your answer Shane. Yes I can see the "Empty" word.
My question now is why the message is on the red box and not under the label like in "Company Name" field (check the attachment). Is the way to show the message under the checkboxes field?

#1498467

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Garen,

This is because these fields are set to required by default.

Usually fields that are set to required will get the message added like your screenshots.

However with our custom validation hook it adds a message to the top to let you know the field is required.

Thanks,
Shane

#1501113

Thank you!