Hi Team,
My custom form validation is not working but previously it was working for another form. I have used the same custom validation script and just changed the function name and form id.
Could you please help me?
// function for validation on Registration form
add_filter('cred_form_validate','nhs_form_validation',10,2);
function nhs_form_validation($field_data, $form_data)
{
//field data are field values and errors
list($fields,$errors)=$field_data;
if ($form_data['id']==3053)
{
//check my_field value
if( $user_email == 'specific-domain.com' ) {
$errors['user_email'] = 'If you are a specific-domain employee, you do not need to register. Just click on the blue button above to access Insight.';
}
//return result
return array($fields,$errors);
}
}
Hi Waqar,
I have changed that variable name, by mistake I have put another one inside IF condition but the validation is still not working and form is still submitting without that validation. What should I do next?
okay, let me take backup and delete some personal data from the site and then you can copy the site. Please let me know, will you take backup/copy of site by urself or should I give you backup file?
During troubleshooting on your website's clone, I noticed that issue with the validation function was resulting from a different snippet named "Honeypot for registration form".
In the function used in that code snippet, the line "return array($fields,$errors);" is placed inside the "if" condition that checks for the specific form:
add_filter('cred_form_validate','honeypot_function',10,2);
function honeypot_function($field_data, $form_data)
{
list($fields,$errors)=$field_data;
if ($form_data['id']=='1349') {
//honeypot field
$honeypot = $_POST['insight-honeypot'];
//check if the honeypot field is filled out.
if ($fields['insight-honeypot']['value']!='')
{
//set error message for field
$errors['insight-honeypot']='Wrong Value';
}
//return result
return array($fields,$errors);
}
}
Whereas that line should be outside the if condition, like this:
add_filter('cred_form_validate','honeypot_function',10,2);
function honeypot_function($field_data, $form_data)
{
list($fields,$errors)=$field_data;
if ($form_data['id']=='1349') {
//honeypot field
$honeypot = $_POST['insight-honeypot'];
//check if the honeypot field is filled out.
if ($fields['insight-honeypot']['value']!='')
{
//set error message for field
$errors['insight-honeypot']='Wrong Value';
}
}
//return result
return array($fields,$errors);
}
Fixing this code snippet will fix the behavior of the validation function used in the other code snippet "NHS Registration Form Validation" too.