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

Last updated: 23-03-2023

Advanced Merge Tagsv1.5.1

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

Read more