Documentation

gwp_substring

With the gwp_substring Modifier for Gravity Forms Merge Tags it’s possible to return a part of value (a substring of the original string). You can use the modifier like this:

:gwp_substring start= length=

The modifier has two arguments:

  • start: how many characters should it skip when using a positive value / where does the substring start. When using a negative value (for example -3), the substring will start the number of characters before the end of the value.
  • length: how many characters should be in the substring / what is the length of the substring.

Example gwp_substring

This example gives back a substring of the value in the Gravity Forms field ‘String’ (with Field ID 1). It skips the first two characters and gives back 3 characters:

{String:1:gwp_substring start=2 length=3}

Offset from the end of the string

When using a negative value for the start of the substring (for example start=-3), the substring will start 3 characters before the end of the value (string).

{String:1:gwp_substring start=-3 length=1}

Use substring in calculations

It is possible to extract a portion of a value for use in calculations. Suppose you have a dropdown field (Dropdown Select:1) in your form that contains a list of products, and you want to set a price for that product and multiply it with a certain amount. You can use the gwp_substring modifier to extract the desired substring based on a starting position and a length.

For example: if you have a Select field with the following choices:

Screenshot of the choices in the form editor with the following Label - Value settings:
A Toy Car - toy_car-000010.50
Toyota - toyota-044999.00
Tesla - tesla-109999.00

You can extract the price information from the value by taking the last 9 characters as a substring. Example formula:

{String:1:gwp_substring start=-9} * {Amount:2}

Demo form with gwp_substring

Frequently Asked Questions

What does the gwp_substring merge tag modifier do?

The gwp_substring modifier lets you extract a specific part of a string from a Gravity Forms field. You control the starting point (start) and optionally the number of characters (length). It’s useful for truncating long input, pulling codes, or extracting just the part you need from structured text.

{Full String Input:1:gwp_substring start="0" length="8"}

What do the start and length parameters mean?

– start defines the position where the substring begins. Use 0 to start at the first character, or a negative number to start that many characters from the end.

– length defines how many characters to include from the start point. If omitted, the substring will extend to the end of the string.

{Full String Input:1:gwp_substring start="9"}  
{Full String Input:1:gwp_substring start="0" length="8"}  
{Full String Input:1:gwp_substring start="-8"}

Can I use gwp_substring in calculations?

Yes! You can extract a numeric portion of a string and use it in a formula. This is especially useful when values contain embedded prices or codes that need to be calculated against another field.

{Product Selection:1:gwp_substring start="-5"} * {Quantity:2}

Does it support special characters and emojis?

Yes. The gwp_substring modifier uses PHP’s mb_substr() function, which supports multi-byte characters. This means it can safely handle emojis, accented letters, and non-Latin scripts without cutting them in half.

{Emoji Field:3:gwp_substring start="0" length="2"}

Last updated: 18-07-2025

Advanced Merge Tagsv1.9.3

To use the functionalities described in this documentation, you'll need to get the GravityWP - Advanced Merge Tags add-on.

Read more