Created
August 14, 2020 16:36
-
-
Save jondcampbell/b308c5b392bc8de006f583ed82dbd3c1 to your computer and use it in GitHub Desktop.
Limit length of first name field in Gravity Forms. Applies to ALL FORMS.
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
add_filter( 'gform_field_validation', 'kuztek_first_name_validation', 10, 4 ); | |
function kuztek_first_name_validation( $result, $value, $form, $field ) { | |
$first_name_max_length = 10; | |
$first_name = rgar( $value, $field->id . '.3' ); | |
if ( $result['is_valid'] && 'name' === $field->type && strlen( $first_name ) > $first_name_max_length ) { | |
$result['is_valid'] = false; | |
$result['message'] = 'Please enter a first shorter name'; | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment