Skip Navigation

[Resolved] cred_form_validate not firing

This support ticket is created 5 years, 2 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
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 2 replies, has 2 voices.

Last updated by christianW-8 5 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#1540769

I am trying to:

I want to integrate additional validations in some forms of the website.
Therefore I integrated the following code into my functions.php

add_filter('cred_form_validate','my_validation',10,2);
function my_validation($error_fields, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$error_fields;
//uncomment this if you want to print the field values
//print_r($fields);
//validate if specific form
if ($form_data['id']==865)
{
//check my_field value
if ($fields['wpcf-telefonnummer']['value']!='correct_value')
{
//set error message for my_field
$errors['wpcf-telefonnummer']='Wrong Value';
}
}
//return result
return array($fields,$errors);
}

Link to a page where the issue can be seen:
hidden link
Testlogin: office@morethandigital.com
PW: Rocket$flyFast

I expected to see:
An Error-Message at the field "Telefonnummer" if the value "correct_value" ist not entered.

Instead, I got:
Nothing

#1540945

Hi, you should drop the wpcf- field slug prefix in the $errors array key:

//check my_field value
if ($fields['wpcf-telefonnummer']['value']!='correct_value')
{
//set error message for my_field
$errors['telefonnummer']='Wrong Value';

It's confusing, but the $fields array keys have the wpcf- prefix while the $errors array keys should not. Please make that change and let me know if the problem is not completely resolved. I can take a closer look.

#1541167

Thank you very much for your quick help! Works now perfectly.