Tidy Names and Emails in Gravity Forms Entries
Trims spaces, lowercases email addresses and capitalizes names in Gravity Forms entries before they are saved, so your lists and CRM exports look consistent.
Opens WPIDE on
Code
add_filter( 'gform_save_field_value', function ( $value, $entry, $field, $form, $input_id ) {
if ( ! is_string( $value ) || ! is_object( $field ) ) {
return $value;
}
$value = trim( $value );
if ( 'email' === $field->type ) {
return strtolower( $value );
}
if ( 'name' === $field->type && ( $value === strtolower( $value ) || $value === strtoupper( $value ) ) ) {
return function_exists( 'mb_convert_case' ) ? mb_convert_case( $value, MB_CASE_TITLE, 'UTF-8' ) : ucwords( strtolower( $value ) );
}
return $value;
}, 10, 5 );
Notes
Names already in mixed case (such as McDonald) are left as typed; only all-lowercase or all-uppercase names are changed.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.