Validation by filter failing
-
I’m trying to set up a validation filter to use a text field as though it were a weak password checker. (Don’t ask — client wants it.)
I have this field in a form:
<label>Passcode (required)
[text* the-passcode]</label>and I have this function in my functions.php:
//—————————————-
add_filter( ‘wpcf7_validate_text*’, ‘custom_passcode’, 20, 2 );function custom_passcode( $result, $tag ) {
if ( ‘the-passcode’ == $tag->name ) {
$the-passcode = isset( $_POST[‘the-passcode’] ) ? trim( $_POST[‘the-passcode’] ) : ”;if ( $the-passcode != ‘test-passcode’ ) {
$result->invalidate( $tag, “You have the wrong passcode.” );
}
}return $result;
}
//—————-
I’ve tried debugging by putting a result->invalidate immediately on entering the function, then returning. That SHOULD have caused the field to fail validation no matter what I put in, but it didn’t, which suggests that the function isn’t getting fired at all.Any ideas? I’m using this as a model: https://contactform7.com/2015/03/28/custom-validation/ It’s three years old — is it deprecated? I haven’t found something newer.
The page I need help with: [log in to see the link]
- The topic ‘Validation by filter failing’ is closed to new replies.