Gform replace merge tags

Available in GF v1.6.2

Description

Use this filter to replace custom merge tags.

You can add custom merge tags via the gform_custom_merge_tags filter.

Usage

<?php
add_filter("gform_replace_merge_tags", "replace_custom_merge_tags", 10, 7);
?>

Parameters

$text
(string) The current text in which merge tags are being replace.
$form
(Form Object) The current form
$entry

(Entry Object) The current entry

$url_encode

(boolean) Whether or not to encode any URLs found in the replaced value.

$esc_html

(boolean) Whether or not to encode HTML found in the replaced value.

$nl2br

(boolean) Whether or not to convert newlines to break tags.

$format

(string) Default "html"; determines how the value should be formatted.

Examples

This example demonstrates how to replace a custom merge tag. The code first searches for the merge tag in the $text. If found, it proceeds to retrieve the value which should replace the merge tag and then returns the newly replaced string.

<?php
add_filter('gform_replace_merge_tags', 'replace_download_link', 10, 7);
function replace_download_link($text, $form, $entry, $url_encode, $esc_html, $nl2br, $format) {
    
    $custom_merge_tag = '{download_link}';
    
    if(strpos($text, $custom_merge_tag) === false)
        return $text;
    
    $download_link = gform_get_meta($entry['id'], 'gfmergedoc_download_link');
    $text = str_replace($custom_merge_tag, $download_link, $text);
    
    return $text;
}
?>

Source Code

This filter is located in common.php

Search the Documentation