Gform_replace_merge_tags not replacing merge tag inside saved entry

Hey there,

I have the below snippet to create a custom merge tag via the gform_replace_merge_tags PHP filter. This is working great and I have successfully used it inside form notifications, which was the intended purpose.

However, one thing I noticed is that the merge tag isn’t being replaced inside the saved entry. Ideally, I’d be able to see the entry exactly how the data was sent in the notification email (in the same way the default merge tags are replaced inside the entry data).

Is this a bug or is there another part I need for this to work like this?

Any help is greatly appreciated!

My code:

add_filter( 'gform_replace_merge_tags', 'replace_reference_number', 10, 7 );
function replace_reference_number( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {
    $custom_merge_tag = '{cstm_reference_number}';
 
    if ( strpos( $text, $custom_merge_tag ) === false ) {
        return $text;
    }
 
    $reference_number = 'REF-' . str_pad($entry['id'], 6, '0', STR_PAD_LEFT);
 
    return str_replace( $custom_merge_tag, $reference_number, $text );
}

Are you using this merge tag as the default value of a field in the form?

Nah I am just using it in the form notification

Could you elaborate on this? I don’t think I’m tracking.

Hey David, looking back, I think I was confused about something and I think it’s okay. Must have been end of Friday hallucinations :sweat_smile:

Thanks for reaching out :slight_smile: I’ll mark this as resolved.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.