Skip to content

Instantly share code, notes, and snippets.

@jondcampbell
Created August 14, 2020 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jondcampbell/b308c5b392bc8de006f583ed82dbd3c1 to your computer and use it in GitHub Desktop.
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.
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