The ultimate guide to the Gravity Forms Conditional Shortcode

The Ultimate Guide to the Gravity Forms Conditional Shortcode

Written by Casey Burridge Marketing Coordinator at GravityKit since 2021, Casey is an expert on Gravity Forms, WordPress, and marketing.

Last updated:

Categories Gravity Forms

You probably know about the Gravity Forms shortcode that allows you to embed forms on pages and posts, but have you heard of the conditional shortcode?

The Gravity Forms “conditional shortcode” allows you to show/hide content based on user-inputs. This is really handy for creating custom confirmation messages or email notifications.

In this post, you’ll find out everything you need to know about the Gravity Forms conditional shortcode including how it works, where to use it and examples of common use-cases.

Ready? Let’s dive in! 🤿👇

What Is the Gravity Forms Conditional Shortcode?

If you’re familiar with conditional logic, you won’t have any trouble understanding the conditional shortcode. But in case you’re not, here’s a quick refresher…

Conditional logic refers to a way of making decisions based on certain parameters. A typical conditional logic statement would be something like “If {user_value} is A, then display B”. 

Here’s an image to help you visualize the decision-making process. As you can see, we begin with a value. Then we assess that value against a certain condition. If the value matches our condition, then we do something (i.e. display certain content). If the value fails to match our condition, then we do something else (i.e. display different content).

A diagram illustrating the decision-making progress involved in conditional logic

💡 Pro tip: To learn more about conditional logic, read our ultimate guide to Gravity Forms conditional logic.

Where Can You Use the Gravity Forms Conditional Shortcode?

With most shortcodes, you can use them anywhere on your website. 

The Gravity Forms Conditional shortcode is a little different. Because the shortcode relies on user values, you’re restricted as to where you can use it.

Here’s where you can use the Gravity Forms conditional shortcode:

  • Confirmation Messages 
    Use the conditional shortcode to display custom messages after the user submits your form. We’ll demonstrate this in our example below.
  • Admin Notification emails
    You can use the conditional shortcode to customize the notification emails that get sent to admins after a user fills out your form.
  • User Notification emails
    You can use the conditional shortcode to customize the notification emails that get sent to users after they submit your form.

To customize your Gravity Forms Confirmations or Notifications, simply edit your form, click on Settings and select either the Confirmations or Notifications tab on the left.

The Confirmations and Notifications tab on the Gravity Forms Settings page

Let’s look at the different parameters that the shortcode takes.

Gravity Forms Conditional Shortcode Parameters 

The conditional shortcode has four required parameters:

  • action
    The action you want to perform. For the conditional shortcode set this to “conditional”.
  • merge_tag
    The merge tag of the field you want to evaluate. 
  • condition
    The condition you want to use to test the content of the merge tag against the specified value. Accepted values are: isnot, is, greater_than, less_than, contains, starts_with, ends_with
  • value
    The value against which you want to compare the merge tag based on the condition you set. 

Here’s a basic template:

[gravityforms action=“conditional” merge_tag=“{merge tag:1}” condition=“is”  value=“user value”]

Content to display if condition is met

[/gravityforms]

Examples of How it Works

Here are some specific examples covering popular use-cases.

Example #1 – Displaying Content Based on the Value of a User’s Submission

Let’s start off with a fairly simple use-case. We’ve got a form on our website that asks the user what type of coffee they like to drink in the morning. There are three choices: Cappuccino, Café Latte or Americano.

Depending on which option the user chooses, we want to change the confirmation message that they see after submitting the form. This is easy to do using the conditional shortcode!

First off, we’ll create a new confirmation and select “Text” as the confirmation type.

A checkbox for choosing the Confirmation type (either text, Page or Redirect)

Inside the text editor, we’ll add the conditional shortcode.

The Gravity Forms Confirmation message editor containing the Gravity Forms conditional shortcode
[gravityforms action="conditional" merge_tag="{I like to start my day with a...:1}" condition="is" value="Cappuccino"]

A cappuccino is an espresso-based coffee drink prepared with steamed milk foam.

[/gravityforms]

Now, when a user selects “Cappuccino” and submits the forms, they’ll see the following message:

A cappuccino is an espresso-based coffee drink prepared with steamed milk foam

But what about if they select “Cafe Latte” or “Americano”? We don’t have a condition for that yet, but we can easily add one.

Three Gravity Forms conditional shortcodes inside the Confirmation message text editor

As you can see, by using three conditional shortcodes, we can have three separate messages that display based on three separate conditions.

Example #2 – Show Content if a Value Exists

Not all form fields are required. Using the conditional shortcode, you can display specific content based on whether a field value exists or not.

[gravityforms action="conditional" merge_tag="{My Field:1}" condition="isnot" value=""]

My Field Label: {My Field:1}

[/gravityforms]

Example #3 – Show Content if a Value is Greater or Less Than a Certain Threshold

The conditional shortcode also allows you to show content based on whether a user value is greater or less than a certain amount.

Let’s go back to our coffee example. Let’s say we decide to poll our users by asking them how many cups of coffee they typically drink per day. 

A form with one field called "Cups of coffee per day".

Now we want to display a custom confirmation message telling them whether or not the amount of coffee they drink is above or below average (3 cups).

[gravityforms action="conditional" merge_tag="{Cups of coffee per day:1}" condition="greater_than" value="3"]

Wow! Your coffee consumption is above the average of 3 cups per day!

[/gravityforms]

If a user submits a value greater than 3, they’ll see this message:

Wow! Your coffee consumption is above the average of 3 cups per day
[gravityforms action="conditional" merge_tag="{Cups of coffee per day:1}" condition="less_than" value="3"]

You drink less coffee than the average coffee drinker in the United States.

[/gravityforms]

If a user submits a value less than 3, they’ll see this message:

You drink less coffee than the average coffee drinker in the United States

In this final example, we’ve written a shortcode that checks for the kind of information that the user requested. 

[gravityforms action="conditional" merge_tag="{Information requested:6}" condition="is" value="Support"]

Here’s a <a href=”https://www.gravitykit.com/support”>link to our support form</a>.

[/gravityforms]

If the user requested support, then they’ll see a confirmation message with a link to our support page!

Here's a link to our support form

Nesting Conditional Shortcodes

You can nest conditional shortcodes to check multiple conditions. To do this, you’ll need to use both the plural [gravityforms] and the singular [gravityform] shortcodes.

Here’s an example:

[gravityforms action="conditional" merge_tag="{favorite coffee:1}" condition="is" value="Cappuccino"]
[gravityform action="conditional" merge_tag="{cups:3}" condition="greater_than" value="2"]

You drink more than two cappuccinos a day!

[/gravityform]
[/gravityforms]

In this example, we’re using nested shortcodes to check for two conditions. So if the user chooses “Cappuccino” as their favorite coffee drink AND drinks more than two cups per day, they’ll see the following confirmation message:

“You drink more than two cappuccinos a day!”

If none or only one of those conditions match, the message won’t display.

Gravity Forms Conditional Shortcode Not Working?

If you find that your conditional shortcode isn’t working, here are a few common issues to help you troubleshoot the problem.

Typos

Check to see if you’ve made any typos. You might have used the wrong merge tag, misspelled a certain value or left out a bracket or a quote somewhere!

Spacing Issues

Spacing issues are really common. Having too many or too few spaces in between parameters can cause problems with your shortcode. Spacing issues can be hard to spot, so make sure to check your code carefully.

Formatting Issues

The most common issue with shortcodes is formatting them incorrectly. For example, each parameter value should be wrapped in double quotes, and each shortcode should  be closed by using a forward slash, i.e., [/gravityforms]

Forgetting to do this will cause your conditional shortcode not to work properly.

Using Conditional Shortcodes in the Wrong Place on Your Site

Another reason you could be experiencing issues is because you’re trying to use the conditional shortcode in the wrong place on your website. For example, the conditional shortcode won’t work on pages or posts. The only place you can use the Gravity Forms conditional shortcode is in confirmations or notification emails. 

Taking Things Further With GravityView’s [gvlogic] Shortcode

The Gravity Forms conditional shortcode is an effective way to display content in confirmation messages and notification emails based on certain conditions. However, the shortcode is not without its limits.

For example, the GF conditional shortcode 

  • Does not support “OR” logic
  • Does not support “AND” logic
  • Supports the “contains” condition but not “not_contains”
  • Can only be used inside Gravity Forms Confirmations and Notifications

If you’re looking for more advanced functionality, you’ll need GravityView’s [gvlogic] shortcode! It’s packed full of powerful features and you can use it anywhere on your website.

Gravity Forms Conditional Shortcode Vs GravityView [gvlogic]

Here’s a handy table comparing the Gravity Forms conditional shortcode to GravityView’s more advanced [gvlogic] shortcode.

FunctionalityGF Conditional ShortcodeGravityView gvlogic Shortcode
Can display information based on conditions you set
Supports “AND” logic
Supports “OR” logic
Can use it anywhere on your website
Can show/hide content depending on whether a user is logged in or not
Integrates with GravityView
Supports the “in” condition
Supports the “not_in” condition
Supports the “greater_than_or_is” condition
Supports the “less_than_or_is” condition
Supports the “not_contains” condition

💡 Pro tip: Learn more about GravityView’s [gvlogic] shortcode. 

Start Experimenting With Conditional Logic!

The Gravity Forms conditional shortcode allows you to show/hide content based on user inputs. Using the shortcode you can create custom confirmation messages and email notifications.

In this post, we introduced you to the Gravity Forms conditional shortcode by showing you how it works, the different parameters it requires and where to use it on your site. We also compared it to GravityView’s more advanced [gvlogic] shortcode.

To learn more about conditional logic in Gravity Forms, read Gravity Forms Conditional Logic: The Ultimate Guide.