Capitalize Input field data on Submit [RESOLVED]

How to capitalize the content of a Gravity Forms input field? I got Form with ID6 and field ID 46 trying to use the following snippet with no luck.

       //Change _6 to the form ID number everywhere
    add_action('gform_pre_submission_6', 'capitalize_fields_6');
    function capitalize_fields_6($form){
            // add all the field IDs you want to capitalize, to this array
            $fields_to_cap = array('input_46');
            foreach ($fields_to_cap as $each) {
                    // for each field, convert the submitted value to uppercase and assign back to the POST variable
                    // the rgpost function strips slashes
                    $_POST[$each] = strtoupper(rgpost($each));
            // return the form, even though we did not modify it
            return $form;

When I input name UPPERCASE no change made on submit.

You can use the snippet below to capitalize the text in a field on submit

    // update "6" to your form ID and "46" to the Field ID
    add_filter( 'gform_save_field_value_6_46', 'uppercase_text', 10, 3 );
    function uppercase_text( $value, $entry, $field ) {
            return strtoupper( $value );
1 Like

Thanks Samuel,

My problem was to transform any UPPERCASE or lowercase to Capitalize, so I have changed your snippet to: // update "6" to your form ID and "46" to the Field ID add_filter( 'gform_get_input_value_6_46', function( $value ) { return ucwords(strtolower( $value )); } );

Thanks for idea. :wink: It works!

© 2008 - 2021. Gravity Forms is a project by Rocketgenius Inc.