Do you want to replace (part of the) text in the ouput of a Gravity Forms Merge Tag? For example to automatically remove spaces or change words in the string? With Advanced Merge Tags you’ll have the gwp_replace Modifier at your disposal to do exactly that. We’ll walk you through it.
Replace Text in Merge Tag output
In this example we automatically want to change gravitywp with GravityWP (because that’s the way we like to write it). We can use the gwp_replace modifier like this:
{Example:1:gwp_replace search="gravitywp" replace="GravityWP"}
There are two parameters in the modifier:
- search: the modifier will search through the value of the Gravity Forms field.
- replace: if it finds the search string, it will replace it with the replace text.
In this example, when in the value of the Merge Tag gravitywp is found, it will be replaced with GravityWP.
Removing spaces from the Merge Tag output
We had several cases with clients where we wanted to trim the spaces (if used) in a value. You can do that by searching on a space and replacing it with nothing:
{Example:1:gwp_replace search=" " replace=""}
In this example, when in the value of the Merge Tag one or more spaces are found, they are automatically removed. You can do the same with any other characters or combination of characters.
Client example: For one of our clients we needed this stripping of spaces in a very specific situations. In the Netherlands, the ZIP code can be in two different formats. It’s always 4 numbers and 2 (capital) letters. It’s asked in Forms in different ways, sometimes with a space and sometimes without, eg. 2901 SA or 2901SA. Our client had the ZIP code data in their Gravity Form as 2901 SA and wanted to automatically change that to 2901SA. With the gwp_replace Merge Tag Modifier that was very easy to accomplish.
Search and replace multiple different texts or characters
You can also use the modifier to replace more parts of a string.
{Example:1:gwp_replace search="gravitywp" replace="GWP" modifier1='gwp_replace search="cool" replace="awesome"'}
Sometimes you want to search and replace more than one word or character in the Merge Tag output. In this case you can use the nested modifiers that is build in the Advanced Merge Tags Add-on for Gravity Forms. Simply add another modifier or multiple modifiers following the above logic. You can use multiple modifiers by adding a number, like modifier2, modifier3 etc.
Demo replacing text Gravity Forms
Our Premium add-ons for Gravity Forms
API Connector
Connect Gravity Forms to External API's: Query the API using form field values and automatically fill other form fields with the API response.
DateTime Field
The GravityWP - DateTime Field add-on adds a dedicated Date/Time field to Gravity Forms so users can enter both a date and a time in a single input.
Update Multiple Entries
Trigger the update of multiple entries in a target form by submitting an entry in a trigger form.
List Number Format
With this Gravity Forms Add-on you can change List Field columns into a number field, do calculations within a row or column. Extra merge tags are available with total counts of columns.
Read tutorials about
Gravity Forms Discount Code Field: Apply Fixed or Percentage Discounts in a Form
Learn how to create a Gravity Forms discount code field that applies fixed or percentage discounts. This tutorial shows how to calculate subtotals, discount amounts, and final totals using tested form logic.
Gravity Forms Zoom Integration: Create Zoom Meetings From Booking Forms
Learn how to connect Gravity Forms to Zoom without Zapier using GravityWP API Connector. This step-by-step tutorial shows how to create Zoom meetings from booking form submissions and save the returned meeting details back to Gravity Forms.
Gravity Forms monday.com Integration: Create New Items From Form Submissions
Learn how to connect Gravity Forms to monday.com without Zapier using GravityWP API Connector. This step-by-step tutorial shows how to create new monday.com items from form submissions and save the returned monday.com item ID back to Gravity Forms.
Gravity Forms Pipedrive Integration: Send Form Contacts to Pipedrive Without Zapier
Learn how to connect Gravity Forms to Pipedrive without Zapier using GravityWP API Connector. This step-by-step tutorial shows how to send form contacts, custom fields, and the returned Pipedrive Person ID directly from WordPress to Pipedrive CRM.