Tap into Gravity Forms “initialization scripts” functionality and register your own scripts to run inline with Gravity Forms. Scripts added via the GFFormDisplay::add_init_script() function will be output with the form(s) they are registered for.


Applies to all forms.

add_action( 'gform_register_init_scripts', 'my_custom_function', 10, 2 );


  • $form Form Object

    The current form.

  • $field_values array

    If any field values were provided in the shortcode or functional call responsible for displaying this form, they will be available here.


This example (via Gravity Wiz), demonstrates how the gform_register_init_scripts hook can be used to register your GF-related initialization scripts using the GFFormDisplay::add_init_script() function.

add_action( 'gform_register_init_scripts', 'gform_format_money' );
function gform_format_money( $form ) {

    $script = '(function($){' .
        '$('.gf_money input').each(function(){' .
            '$(this).val(gformFormatMoney($(this).val()));' .
        '}).change(function(){' .
            '$(this).val(gformFormatMoney($(this).val()));' .
        '});' .

    GFFormDisplay::add_init_script( $form['id'], 'format_money', GFFormDisplay::ON_PAGE_RENDER, $script );


This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in GFFormDisplay::register_form_init_scripts() in form_display.php.