Handy Gravity Forms filters

Gravity Forms has plenty of filters to customize your forms. We wrote very short articles in the past about filters we use a lot and decided to bring them all to this page for reference.

Capitalize fields in Gravity Forms

How to capitalize the content of a Gravity Forms input field? There are two possible angles. If you just want to display the content of a field in Uppercase, use the CSS. If you want to convert the user input to Uppercase while submitting the form, use the PHP solution.

Capitalize a form field with CSS for visual purpose

First you need the form ID and the field ID. Then add the following code to your CSS. Of course you need to change the Form and Field ID number. The correct CSS selector is ‘#input_FormID_FieldID’.

#input_6_1 {      /*based on FormID and FieldID*/
    text-transform: uppercase;

Capitalize a form field with PHP before entry

First you need the form ID and the field ID. Then add the following code to your functions.php. Of course you need to change the Form and Field ID number.

//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_6_1');
        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;

Change expiration date Save and continue Gravity Forms

Do you want to change the expiration date for Gravity Forms ‘Save and continue’ functionality (standard 30 days)? This is easily done by adding filter in the functions.php file in your theme folder.

How to change the expiration date in Gravity Forms Save and continue?

Just add the code below to the functions.php file in your theme folder.  By changing the $expiration_days value you can set the number of days the form will be saved.

add_filter( 'gform_incomplete_submissions_expiration_days', 'gwp_days', 1, 10 );
function gwp_days( $expiration_days ) {
    // change this value
    $expiration_days = 365;
    return $expiration_days;

Zip-code before City in Gravity Forms (order of address field)

Do you want to change the order of the Gravity Forms Address field items? Especially to put the ZIP-code before the City (as is usual in Germany and the Netherlands for example)? Here you find the easiest way.

How to change the ZIP-code field location in your Gravity Form

Copy this code in your functions.php in your theme directory and the zip-code will show before the City instead of after it.

add_filter( 'gform_address_display_format', 'address_format' );
function address_format( $format ) {
    return 'zip_before_city';

Go to the top after Next or Submit Gravity Forms

When you use pages in your Gravity Forms (people click Next to go to the next page in the form) or when people submit their form, you may want to automatically have the page centred at the top of your website. This is very easy to do. It makes it much friendlier for visitors of your form, because they know that they start from the same point after clicking a button (Next or Submit).

How to create a top anchor in a multi page Gravity Form

Add the following code to your functions.php theme file. After people click Next or Submit, the page will be automatically outlined at the top of the page.

add_filter("gform_confirmation_anchor", create_function("","return 0;"));

WordPress Multi Site Gravity Forms License

If you use Gravity Forms in a Multi Site install of WordPress, and you create new sites,
you may want to add the Gravity Forms license key automatically to your new site.

How to automatically add Gravity Forms License key (and more) to multi-site installs

This is an easy way to prepopulate your Gravity Forms license key when new sites are created on a multi-site install. Add the following code to the wp-config.php file. More interesting multi-site automation options are described in de Gravity Forms documentation.