Using Gravity Forms ‘gform_editor_js’ PHP action

The gform_editor_js action hook is used to inject JavaScript into the form editor page.

Usage

add_action('gform_editor_js', 'editor_script');

Parameters

  • No parameters for this action hook.

More information

See Gravity Forms Docs: gform_editor_js

Examples

Basic Example

Inject a simple script into the form editor page.

add_action('gform_editor_js', 'editor_script');
function editor_script() {
    echo '<script type="text/javascript">//do something</script>';
}

Adding a Custom Setting to All Field Types

Add a custom setting to all field types implemented using gform_field_standard_settings, gform_field_appearance_settings, or gform_field_advanced_settings.

add_action('gform_editor_js', function () {
    echo '<script type="text/javascript">' . PHP_EOL;
    foreach (GF_Fields::get_all() as $gf_field) {
        echo 'fieldSettings.' . $gf_field->type . ' += ", .encrypt_setting";' . PHP_EOL;
    }
    echo '</script>' . PHP_EOL;
});

Set Default Date Format

Set the default date format for date type fields to dmy_dot.

add_action('gform_editor_js', function () {
    echo '<script type="text/javascript">function SetDefaultValues_date(field){field.dateFormat = "dmy_dot";}</script>' . PHP_EOL;
});

Collapse All Sections by Default

Collapse all sections in the form editor by default.

add_action('gform_editor_js', function () {
    echo '<script type="text/javascript">jQuery(document).ready(function() { jQuery(".gsection").addClass("gsection_collapsed"); });</script>' . PHP_EOL;
});

Disable Form Title Editing

Prevent users from editing the form title in the form editor.

add_action('gform_editor_js', function () {
    echo '<script type="text/javascript">jQuery(document).ready(function() { jQuery("#form_title").prop("disabled", true); });</script>' . PHP_EOL;
});