gform_merge_tags

Description

Allows merge tags to be added/removed from the Merge Tag drop down in the admin.

Usage

<script type="text/javascript">
gform.addFilter('gform_merge_tags', 'add_merge_tags');
function add_merge_tags(mergeTags, elementId, hideAllFields, excludeFieldTypes, isPrepop, option){
    //do something here
    return mergeTags;
}
</script>

Parameters

  • mergeTags object
    The current mergeTags
  • elementId string
    The name of the current field. When selecting the Merge Tag drop down on the Advanced tab of a form field, the value will always be “field_default_value”. The confirmation and notification admin pages will return specific field names so you may target adding a merge tag to a specific field.
  • hideAllFields boolean
    Indicates whether to include the “All Submitted Fields” choice in the Merge Tag drop down.
  • isPrepop boolean
    Indicates whether to include form fields in the Merge Tag drop down.
  • option string
    Internal use by Gravity Forms.

Examples

Merge tags are currently grouped as ungrouped, required, optional, pricing, other, custom. Each group has a child object named tags, within tags is tag and label. Label is the text which displays in the merge tag drop down and tag is the merge tag {my_custom_merge_tag}.

Add custom merge tags to dropdown

This example adds 3 new merge tags to the drop down; two “custom” tags named “My Custom Merge Tag 1” and “My Custom Merge Tag 2”, and one “required” named “My Required Merge Tag 1”.

gform.addFilter('gform_merge_tags', function (mergeTags, elementId, hideAllFields, excludeFieldTypes, isPrepop, option) {
    mergeTags["custom"].tags.push({tag: '{custom_merge_tag1}', label: 'My Custom Merge Tag 1'});
    mergeTags["custom"].tags.push({tag: '{custom_merge_tag2}', label: 'My Custom Merge Tag 2'});
    mergeTags["required"].tags.push({tag: '{required_merge_tag1}', label: 'My Required Merge Tag 1'});
    return mergeTags;
});

Remove a merge tag from the dropdown

This example removes the “Client IP Address” merge tag from the “other” group.

gform.addFilter("gform_merge_tags", function (mergeTags, elementId, hideAllFields, excludeFieldTypes, isPrepop, option) {
    //remove client ip address from "other" group
    for (i in mergeTags["other"].tags) {
        if (mergeTags["other"].tags[i].tag == "{ip}") {
            mergeTags["other"].tags.splice(i, 1);
        }
    }
    return mergeTags;
});

Source Code

This filter is located in form_admin.js