Problem: I am trying to validate a custom field with cred_form_validate, but I cannot validate a specific field. Errors never appear in the form.
Solution: Be sure to include the form_messages field in the Form builder so errors can be displayed. Then use the following syntax to validate a custom field:
function fn_cred_form_validate($error_fields, $form_data)
{
list($fields,$errors)=$error_fields;
if ($form_data['id']==221) {
if (empty($fields['wpcf-application-tour-number']['value'])) {
//set error message for my_field
$errors['application-tour-number']='Please select tour first';
}
}
return array($fields,$errors);
}
add_filter('cred_form_validate','fn_cred_form_validate',10,2);
Notice that the wpcf- prefix is required in the $fields array, but should not be included in the $errors array.