Last active
April 29, 2022 21:23
-
-
Save rickgregory/ec2155f20b4becc662c017137b231edb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//validation for name field in GF to prevent nonsense spam names. Rejects any string with 4 consecutive consonants. | |
add_filter( 'gform_field_validation', 'validate_name', 10, 4 ); | |
function validate_name( $result, $value, $form, $field ) { | |
if ( 'name' === $field->type && $field->isRequired ) { | |
GFCommon::log_debug( __METHOD__ . '(): Name values => ' . print_r( $value, true ) ); | |
$pattern = "/(?=[a-z]{4})[^aeiou]{4}/"; | |
if ( !preg_match( $pattern, $value ) ) { | |
$result['is_valid'] = false; | |
$result['message'] = 'Please enter a valid name'; | |
} else { | |
$result['is_valid'] = true; | |
$result['message'] = 'You may pass'; | |
} | |
GFCommon::log_debug( __METHOD__ . '(): Result => ' . print_r( $result, true ) ); | |
return $result; | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment