Using Gravity Forms ‘gform_enqueue_scripts’ PHP action

The gform_enqueue_scripts action is executed during the process of enqueuing scripts for each form on the current page. It is useful when developing custom field types that require extra scripts.

Usage

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

For a specific form, add the form ID after the action name:

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

Parameters

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

More information

See Gravity Forms Docs: gform_enqueue_scripts

Examples

Enqueue custom script for AJAX forms

add_action('gform_enqueue_scripts', 'enqueue_custom_script', 10, 2);
function enqueue_custom_script($form, $is_ajax) {
    if ($is_ajax) {
        wp_enqueue_script('custom_script', 'path/file.js');
    }
}

Dequeue stylesheets for a specific form

add_action('gform_enqueue_scripts_1', 'dequeue_gf_stylesheets', 11);
function dequeue_gf_stylesheets() {
    wp_dequeue_style('gforms_reset_css');
    wp_dequeue_style('gforms_datepicker_css');
    wp_dequeue_style('gforms_formsmain_css');
    wp_dequeue_style('gforms_ready_class_css');
    wp_dequeue_style('gforms_browsers_css');
}

Manually include RTL stylesheet

add_action('gform_enqueue_scripts', 'enqueue_custom_script');
function enqueue_custom_script() {
    $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG || isset($_GET['gform_debug']) ? '' : '.min';
    wp_enqueue_style('gforms_rtl_css', GFCommon::get_base_url() . "/css/rtl{$min}.css", null, GFCommon::$version);
}

Dequeue script for a specific form

add_action('gform_enqueue_scripts_1', function() {
    wp_dequeue_script('gform_placeholder');
}, 11);

Place this code in the header.php file of your active theme just before the wp_head() function call or in a custom functions plugin.

This action is located in GFFormDisplay::enqueue_form_scripts() in form_display.php.