Using Gravity Forms ‘gform_print_scripts’ PHP action

The gform_print_scripts action hook is executed just after the scripts are printed to the page for the form widget or when a form embed is processed in a custom location using GFCommon::gform_do_shortcode().

Usage

add_action('gform_print_scripts', 'your_function_name', 10, 2);

You can also specify this per form by adding the form id after the hook name.

add_action('gform_print_scripts_6', 'your_function_name', 10, 2);

Parameters

  • $form (Form Object) – The current form object.
  • $is_ajax (bool) – Indicates if the form is configured to be submitted via AJAX.

More information

See Gravity Forms Docs: gform_print_scripts This filter was added in Gravity Forms v2.5. Source Code: This filter is located in GFFormDisplay::print_form_scripts() in form_display.php.

Examples

This example prints a custom script for all AJAX enabled forms.

add_action('gform_print_scripts', 'print_custom_script', 10, 2);

function print_custom_script($form, $is_ajax) {
    if ($is_ajax) {
        wp_enqueue_script('custom_script', 'path/file.js');
        wp_print_scripts('custom_script');
    }
}