Custom Validation Problem
-
I am trying to get custom validation to work on checkboxes and following your email fields example. But in my custom validation function for some reason $tag->name has no value when passed to the function. So the only way I could get it to work was by removing the test for the tag name (show below commented out). The problem with that is, of course, now it triggers regardless of which field is being validated and shows an error for every checkbox.
Any idea what might be going wrong? Thanks in advance for any help!
—————–
add_filter( ‘wpcf7_validate_checkbox’, ‘custom_checkbox_confirmation_validation_filter’, 20, 2 );function custom_checkbox_confirmation_validation_filter( $result, $tag ) {
//if ( ‘checkbox-1’ == $tag->name ) {
$checkbox_1 = isset($_POST[‘checkbox-1’]) && $_POST[‘checkbox-1’] ? “1” : “0”;
$checkbox_2 = isset($_POST[‘checkbox-2’]) && $_POST[‘checkbox-2’] ? “1” : “0”;
$checkbox_3 = isset($_POST[‘checkbox-3’]) && $_POST[‘checkbox-3’] ? “1” : “0”;
if ( $checkbox_1 == 0 && $checkbox_2 == 0 && $checkbox_3 == 0 ) {
$result->invalidate( $tag, “You must check at least one box! ” . $tag->name);
}
//}
return $result;
}
- The topic ‘Custom Validation Problem’ is closed to new replies.