Change UPPERCASE entries to Capitalized upon submission?

Trying to find a way to change case of submitted entries from uppercase to capitalized. I’ve seen some snippets here that can successfully change all or selected entries to uppercase, but none that can take uppercase entries and convert to capitalized.

I’ve found CSS can be used to convert lowercase entries to capitalized or uppercase or vice versa, but haven’t had any luck changing uppercase entries to capitalized.

The issue: client has mostly foreign students applying via GF. In some countries, apparently filling out entire form in uppercase is standard, but this makes using submitted data cumbersome as they have to retype entries when used in merges.

Any advice appreciated.

Hello. You can use one of those snippets with the PHP ucwords function:

https://www.php.net/manual/en/function.ucwords.php

For example, this filter would work with ucwords vs strtoupper:

1 Like

Thank you Chris. From those resources, I was able to cobble together something that works on text, name, and address field types.

add_filter( 'gform_save_field_value', 'uppercase_text', 10, 3 );
function uppercase_text( $value, $entry, $field ) {
	$t=$field->get_input_type() ;
    if ( ($t == 'text') || ($t == 'name') || ($t == 'address')) {
        $value = ucwords(strtolower($value),"^ \t\r\n\f\v");
    }
    return $value;
}

Researching now how to apply to list fields as well. Any recommendations?

Again - many thanks!

Hello. I think I would use the built in logging in Gravity Forms to see what the $entry and $value look like, so you can see how to access them. First, enable Gravity Forms logging:

Then add a logging statement to your uppercase_text function so that you can see what the $value and the $entry look like.

You can add these lines to your existing function, right before the $t= line:

GFCommon::log_debug( __METHOD__ . '(): ENTRY => ' . print_r( $entry, true ) );
GFCommon::log_debug( __METHOD__ . '(): VALUE => ' . print_r( $value, true ) );

That is going to log the entry a bunch of times which is redundant, but it will show you the entry.

Let us know what you find out.

1 Like

That’s a great idea. Thank you. Will report back. Cheers!