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
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.
Thank you very much for your quick help! Works now perfectly.