Append and Prepend Values to Gravity Forms Merge Tags

Append and prepend values to Gravity Forms merge tags anywhere that they are supported. Customize how your forms display information dynamically.

Overview

This plugin adds support for appending and prepending values to Gravity Forms merge tags anywhere they are supported. How does this work?

Populate Anything lets you populate field choices and values with information from any source.

Populate Anything’s Live Merge Tag feature allows you to populate the value input in one field to another heading, label, description, or anywhere else on your form. For example, you may have a user enter their address in one field, and want to display this address as HTML content in subsequent form sections.

Our customers do amazing things with Live Merge Tags. Recently, a customer wanted to add a value to a merge tag in their form. They were already using Populate Anything’s Live Merge Tag feature to populate the value from one field to the heading of another field, but they wanted to add some additional content to the value.

While they could easily just add some static content after the merge tag, the problem they ran into was that the static content would always show. Instead, they wanted the appended value to be a part of the merge tag, so that if there’s no value present, then nothing is displayed.

We thought that was a great idea, so we created a plugin to do just that. Let’s dive in.

  1. Overview
  2. Using the Plugin
    1. Prerequisites
    2. Using the Merge Tag Modifiers
  3. Taking It Further
    1. Step 1 – Add a Name and Signature Field to your Form
    2. Step 2 – Add Live Merge Tag and Modifiers
  4. Known Limitations
  5. Wrapping Up

Using the Plugin

Prerequisites

Confirm that you have Gravity Forms installed and activated and that you’ve installed the plugin.

Using the Merge Tag Modifiers

This plugin adds two merge tag modifiers to prepend and append values: :append[] and :prepend[]. To use them, insert a merge tag anywhere they’re supported, and add the modifier. Insert the value you want to add in between the square brackets. Below is an example where the value of the First Name field will be output as “Scott’s address.”

# Scott's address
{Name (First):2.3:append['s address]}

Prepending a value works the same way.

# Your Pin: 1234
{One-time Pin:1:prepend[Your Pin: ]}

Like other merge tag modifiers, they can be combined in a single merge tag.

# Hello, Scott the Magnificent!
{Name (First):2.3:prepend[Hello, ],append[ the Magnificent!]}

Taking It Further

While this plugin works perfectly by itself, it really shines when combined with Populate Anything. Appending and prepending values to Gravity Forms Merge Tags gives you ultimate flexibility in displaying previously entered information to users on the form.

For example, let’s say you have a form that includes a Name and Signature field. You can use Live Merge Tags to display the entered name in the Signature field’s label. Combine that with an appended value and a fallback modifier, and the customized field label is only shown when the user has entered a value in the name field. Let’s walk through setting that up.

Step 1 – Add a Name and Signature Field to your Form

Start by adding a Name and Signature field to your form. Make a note of the Name field’s ID when adding it. You’ll be using this later.

add a name and signature to your gravity forms

Step 2 – Add Live Merge Tag and Modifiers

Next, add the Live Merge Tag for the Name field into the Field Label for the Signature field.

@{Name (First):2.3}

Then, add the :append[] merge tag modifier to your Live Merge Tag.

@{Name (First):2.3:append['s signature]}

Lastly, add the :fallback[] merge tag modifier. This is the value that will display if no value is present.

@{Name (First):2.3:append['s signature]:fallback[Signature]}

With the full merge tag in place, it will look a bit cramped in the field settings.

gravity forms merge tags

However, you can view the merge tag in full above the field in the form builder.

live merge tags in gravity forms

When the form is loaded, the Signature field’s label is simply “Signature”.

gravity forms merge tags in html field

When a user enters their name in to the Name field, the Signature field updates automatically to display “Name‘s signature”.

gravity forms live merge tag info

Known Limitations

  • Gravity Forms lower-cases all modifier values by default. A value of “Hello” will be rendered as “hello”.
  • The comma (,) is a reserved character in Gravity Forms merge tags. Use the following HTML entity instead. ,

Wrapping Up

Live Merge Tags let you display dynamic data throughout your forms, and by appending and prepending values, you can customize Gravity Forms to display additional information according to your needs. This simple plugin is powerful and flexible. Let us know how you’re using it. We would love to hear from you!

Comments

  1. William
    William March 27, 2023 at 8:34 pm

    Hmmm, this doesn’t seem to work when using a merge field to BCC a notification. It returns the error: Please enter a valid email address or merge tag in the BCC field.

    This is the merge tag: {RecordID:39:prepend[a-L],append[-AY2VP81@examplesite.com]}

    The Record ID is incorporated into an email address that will automatically update the lead record in our CRM.

    Reply
    1. David Smith
      David Smith Staff March 29, 2023 at 4:05 pm

      Hey William, this is being blocked by Gravity Forms’ aggressive merge tag validator. I’m not sure we can easily bypass this but… you could achieve the same effect by adding a hidden Email field on your form and setting the default value using Live Merge Tags:

      @{RecordID:39:prepend[a-L],append[-AY2VP81@examplesite.com]}

    2. Christoph
      Christoph April 6, 2024 at 7:48 am

      I want to solve exactly the same problem and used David’s guidance. But I can’t get it to work! The field populates with the content of the other field but keeps ignoring the prepend and append parameters. I have GP Populate Anything version 2.0.37 (the latest from 3 days ago). Is there a bug or something additional that I’d need to activate?

      This is my Default Value in the hidden email field:

      @{DealID:26:prepend[xxxxx+deal],append[@pipedrivemail.com]}

      I tried debugging like this:

      @{DealID:26:prepend[A],append[B]}

      But I only get the number, not the prepends or appends. Please advice.

    3. Christoph
      Christoph April 6, 2024 at 1:12 pm

      I actually want to solve exactly the same problem like William and followed David’s guidance. But I can’t get it to work. I run the latest version (2.0.37) of GP Populate Anything.

      I get the ID number into the other field but the append and prepend parameters just don’t show up. I tried debugging with only using one of them, only using a single character etc.

      Is there a known bug in the current version? Or anything else I’d need to activate?

    4. Samuel Bassah
      Samuel Bassah Staff April 8, 2024 at 7:55 am

      Hi Christoph,

      I just tested this with the merge tag you’re using, and it works as expected. Can you please confirm if you’ve added the snippet referenced on this page to your website? If not, please get the link to the snippet at the top of this page and test it. The snippet handles the prepend and append feature. However, if you already have the snippet, and it’s still not working for you, submit a ticket with us via our support form so we can dig into this further.

      Best,

    5. Christoph
      Christoph April 9, 2024 at 7:19 am

      Thank you Samuel! No, I had totally missed the part where I need to add code. Found it, implemented it. Works like a charm! Thanks a lot!

    6. Samuel Bassah
      Samuel Bassah Staff April 9, 2024 at 7:49 am

      Hi Christoph,

      You’re welcome. Glad we to know it’s working for you now.

      Best,

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Download Plugin

Append and Prepend Values to Gravity Forms Merge Tags

This field is for validation purposes and should be left unchanged.