The Bundle Up! Black Friday Sale Is Live!
Countdown timer

Gravity Forms Conditional Logic: The Ultimate Guide

"Gravity Forms Conditional Logic". The Gravity Forms logo next to an icon representing conditional logic

🚀

All the different ways to use conditional logic inside Gravity Forms. Hiding form fields, displaying content based on user inputs, using the powerful shortcode, and more.

Estimated reading time: 21 minutes

Conditional logic is a powerful way to optimize your Gravity Forms and create a more personalized user experience on your WordPress website.

Research shows that it only takes users 50 milliseconds to form an opinion about your site!

Yes, that’s right – Internet users have very short attention spans. If your content isn’t relevant and easy to navigate, visitors will exit the page.

The same thing goes for forms: you need to simplify your forms to keep users’ attention!

Forms are a powerful marketing tool. You can use them to collect leads, survey your customers, sell products, and much more. But if your forms are long and complicated, users are going to lose interest long before they click “submit”.

If you’re not using conditional logic on your forms, you should be! In this guide, we will look at all the ways you can use conditional logic inside Gravity Forms to improve the functionality of your website.

Keep reading to find out everything you need to know about Gravity Forms conditional logic.

What Is Conditional Logic?

Conditional logic is a way of making decisions based on certain parameters. It’s a process that says “If X, then do Y, but if Z then do W”.

Conditional logic is a big part of Gravity Forms. Conditional logic gives you the ability to create powerful forms that hide or display fields based on certain rules being met. But conditional logic doesn’t end there.

You can use conditional logic to send notifications to users based on certain information or display different confirmation messages depending on what the user entered in their submission.

With GravityView’s powerful [gvlogic] shortcode, you can also use conditional logic on posts, pages, or anywhere on your WordPress website.

Why Is Conditional Logic Important?

Conditional logic allows you to build interactive forms that display relevant fields and improve the overall user experience.

Think about it. If your forms contain fields that users find irrelevant, they are less likely to complete the sign-up process. Users are more willing to invest time into businesses that connect with them on a personal level.

But conditional logic in Gravity Forms isn’t limited to form fields. You can use conditional logic to deliver relevant, personalized messages to users in a variety of ways.

  • Display different information to a user depending on their role  
  • Personalize email notifications 
  • Send relevant confirmation messages
  • Create powerful, complex workflows

Here are some examples of how this works.

Gravity Forms Conditional Logic Examples

So you can see the importance of conditional logic but you’re still confused about how it works? Here are some examples of conditional logic in action.

Display or Hide Form Fields

Okay, so let’s say you want to survey your readers to find out how many of them enjoy drinking coffee and what their favorite type of coffee is.

Here, we have a simple form that asks for the reader’s name and then asks them whether they drink coffee. If they select “No”, that’s the end of the form. They can click “Submit” and everything is done.

A form with a Name field and a dropdown field that says "Do you drink coffee?" with the answer showing as "no"

But if they select “Yes”, a new field appears asking them whether they prefer lattes, cappuccinos, or americanos.

the "do you drink coffee" now shows as "yes" and another checkbox field is displaying asking "What's your favorite kind?"

Although this is a simple example, do you see how we have simplified the user experience? It wouldn’t make much sense to ask the user what their favorite kind of coffee is if they already told us they don’t drink coffee!

Here we’re using conditional logic to display the last field when the user selects “Yes” and keep it hidden when the user selects “No”.

Gravity Forms Confirmation Conditional Logic

We can use conditional logic to show different confirmation messages depending on what information the user entered in our form.

So when a user tells us that their favorite type of coffee is a cappuccino, here’s what they’ll see after submitting the form:

A message that says "I also LOVE Cappuccinos! Thanks for taking part in the survey"

But if they check the box that says Americano, they’ll see this:

A message that says "Did you know the name 'Americano' comes from the Italian 'Caffee Americano', which means 'American coffee'?"

Hide Content for Logged-out Users

Using GravityView’s shortcode (more on this later!) you can show or hide content on your website based on whether a user is logged in or not.

For example, let’s say you had an article that you wanted to restrict to members only. When a new user tries to view the page, here’s what they would see.

A message that says "Uh oh! You need to log in before viewing this content."

But when a logged-in user opens the same page, they see this:

A message that says "Congrats! You're logged in! Here's some content..."

These are just a few examples of how you can use conditional logic to create a personalized experience for your users. 

How to Use Conditional Logic in Gravity Forms

Now that you know how conditional logic works, let’s look at how you can implement it on your website.

Show or Hide Form Fields

Hover over Forms in the left-hand menu, click New Form and add your desired fields. Next, click on a field that you want to show or hide.

The form builder in Gravity Forms with an arrow pointing to the "Conditional Logic" tab under "Field Settings".

Under Field Settings, click on Conditional Logic. If you’re using the Gravity Forms 2.5 or later, the conditional logic settings will open in a new window that slides in from the right-hand side.

Toggle to enable conditional logic and then set your conditions below.

The Gravity Forms conditional logic fly-out menu with a slider to enable conditional logic

Enabling Conditional Logic for Gravity Forms Notifications

You can use conditional logic to determine which notification to send to a user based on the information they enter into your form.

Go to your forms page, hover over your form, hover over Settings, and then click on Notifications.

An arrow pointing to the "Notifications" link under "Settings"

Edit your existing notification or create a new one. Now scroll down right to the bottom of the page where it says “Conditional Logic” and enable it.

A checkbox labeled "Enable conditional logic"

In this example, we’re only sending this notification to users who chose “Americano” as their favorite type of coffee.

Gravity Forms Feeds

You can also use conditional logic for your Gravity Forms feeds.

A feed is a notification that sends information to an add-on or external service when a user submits your form.

External services refer to anything outside of Gravity Forms. This includes CRMs like Salesforce, storage services like Dropbox, and other third-party applications.

Feeds are part of what makes Gravity Forms such a powerful and flexible form plugin. Using conditional logic on feeds gives rise to a whole new set of possibilities.

To create new feeds for your forms, you’ll need to install an add-on that supports feeds, such as the Gravity Forms User Registration add-on or the GravityView Calendar add-on.

Conditional User Registration

You can view your form feeds by going to the form settings. You’ll see different feeds appear in the left-hand sidebar.

In this example, we’re going to create a user registration feed and then conditionally register users on our site depending on what information they entered into the registration form.

If you don’t have a user registration feed set up yet, click Add New.

The "User Registration" feed in Gravity Forms

Configure your feed and then scroll down to the bottom where it says “Registration Condition” and check the box to enable it.

A checkbox labeled "Registration Condition"

In this example, we have set it to only register users with a “@mysite.com” email address.

Conditionally Display Events on a Calendar

Using the Gravity Forms Calendar plugin by GravityView, you can display form entries as events on a calendar.

After installing and activating the plugin, you’ll be able to configure new calendar feeds linked to your form in Gravity Forms.

After setting up a new feed, scroll down and enable conditional logic. You can now choose how events are displayed based on conditions that you set.

In this example, the calendar will only display events organized by “Mandy”.

A checkbox labeled "Enable Condition" with a condition set up to process the feed only if the Event Organizer is Mandy.

In this section, we looked at using conditional logic on feeds to add more flexibility to Gravity Forms.

Conditional Logic for Product Pricing

The Gravity Forms Product field enables you to sell products using Gravity Forms. But what if you want to adjust the price of your products based on the order quantity?

You can do this using the Conditional Pricing add-on by GravityWiz. This add-on allows you to create unlimited pricing levels for your Gravity Forms Product fields.

After installing the add-on, create a new form in Gravity Forms, open up the Pricing Fields tab and add a Product field.

The different Gravity Forms Pricing Fields, with the "Product" field highlighted

Now update your form, hover over Settings and click on Conditional Pricing. Choose your product from the dropdown menu and create a new pricing level.

The "Conditional Pricing" settings in Gravity forms

In this example, the regular cost of our product is $15, but we’ve decided to lower it to $10 if the customer orders 10 or more.

So as you can see, with an order quantity of 5 units, the price stays at $15.

A product form showing the "price" as $15.00 and the "Quantity" as 5.

But if the customer changes the quantity to 10, the price automatically becomes $10.

A product form showing the "price" as $10.00 and the "Quantity" as 10.

Using the Conditional Pricing add-on is a simple way to create products with variable prices in Gravity Forms.

Gravity Forms Complex Conditional Logic With the Conditional Shortcode

Most people are unaware that Gravity Forms includes a conditional shortcode that allows you to conditionally display information based on the values a user enters in their submission.

The basic shortcode template looks like this:

[gravityforms action="conditional" merge_tag="" condition="" value=""]
Content to display.
[/gravityforms]

The shortcode accepts the following four parameters:

  • action (always “conditional”)
  • merge_tag (the merge tag for the field value you want to evaluate
  • condition (is, isnot, greater_than, less_than, contains, starts_with, or ends_with)
  • value (the value compared against the value of the merge tag

Here’s how you can use this shortcode to display different confirmation messages to your users.

Conditional Confirmation Messages

You can use the conditional shortcode inside a confirmation, to display a different message to the user depending on the information they submitted.

Go to the forms page, hover over your form, hover over Settings, and click on Confirmations.

An arrow pointing to the "Confirmations" link under "Settings".

Next, click the Add New button in the top right corner to add a new confirmation. You can now use the [gravityforms] conditional shortcode to create a dynamic confirmation message. 

Note: To add a merge tag, click the button on the right side of the text editor.

The Gravity Forms Confirmation text editor containing the "gravityforms" conditional shortcode. The button to add merge tags is also highlighted.

In this example, we’re checking what the user’s favorite kind of coffee is and displaying a different message depending on which one they choose.

Nesting Shortcodes

You can nest shortcodes to create more complex conditional logic. Nesting conditional shortcodes in Gravity Forms requires you to use the plural [gravityforms] and the singular [gravityforms].

Here’s what the basic structure looks like:

[gravityforms action="conditional" merge_tag="" condition="" value=""]
[gravityform action="conditional" merge_tag="" condition="" value=""]
Your content
[/gravityform]
[/gravityforms]

Nesting is helpful if you want to evaluate more than one condition. The [gvlogic] shortcode also supports multiple conditions (more on this below).

Gravity Forms Conditional Logic Shortcode Limitations

While the [gravityforms] conditional shortcode is a good way to dynamically display content depending on the information a user enters in their submission, it’s not without its limitations.

First off, the shortcode can only evaluate the following conditions:

  • is
  • isnot
  • greater_than
  • less_than
  • contains
  • starts_with
  • ends_with

The shortcode does not support “greater than or equals” or “less than or equals”. And while the shortcode supports “contains” it does not support “not contains”.

Furthermore, the shortcode does not support matching values in fields that are JSON-encoded, such as the List and Multiselect fields. 

And finally, the [gravityforms] shortcode only supports two nesting levels, which is a limitation if you need to evaluate more than two conditions.

Gravity Forms Conditional Logic Not Working?

If you’ve configured conditional logic in Gravity Forms and it’s not working as expected, it may be due to one of the following reasons:

  • There’s a plugin or theme conflict
    The most common reason for conditional logic not working is a plugin or theme conflict. To test whether this is the issue, follow this helpful guide.
  • You have an optimization plugin installed that’s interfering with the JavaScript required to implement the conditional logic
    Some WordPress optimization plugins improve page speed by implementing aggressive caching or minifying. This may be causing the conditional logic not to function properly. Disable any optimization plugins and try again.
  • You’re testing the changes from a cached version of the page
    If you’re using a caching plugin on your site, clear your cache and then test the changes again.

Gravity Forms Advanced Conditional Logic With [gvlogic]

GravityView is a plugin that extends Gravity Forms by allowing you to display form entries on the front end of your website.

If you have GravityView installed on your website, you can use the [gvlogic] shortcode to display content based on conditions that you set.

You can use the [gvlogic] shortcode anywhere on your WordPress website – This includes pages, posts, Views, widgets, confirmations, notifications, and more!

[gvlogic] supports more parameters than the [gravityforms] conditional shortcode and it also allows you to restrict content to logged-in users. Here’s how it works.

Constructing an if/else Statement

Using [gvlogic] you can construct if/else statements that allow you to display content based on conditions that you set. An “if” statement says “if X then do Y, else do Z”.

Here’s what the basic template looks like:

[gvlogic if="{field}" is="Value"]
	Text you want to display
[else]
 	Display this instead
[/gvlogic]

For the “if” parameters, we set it equal to a Gravity Forms field value using a merge tag. “Is” refers to the value we want to compare it against.

If we rewrite the above confirmation using [gvlogic] instead of the [gravityforms] conditional shortcode, here’s how it looks.

The Gravity Forms Confirmation text editor containing the "gv logic" shortcode

As you can see, it only requires a few lines of code. You can display any kind of content using [gvlogic]. This includes HTML, other shortcodes, and more.

Parameters

One of the reasons [gvlogic] is so powerful is because it accepts several parameters, including:

  • if (Required, unless you’re using the logged_in parameter)
    • The if parameter accepts Gravity Forms Merge Tags
  • logged_in (Required, unless you’re using the if parameter)
  • is or equals (Required if you’re using the if parameter)
  • else

Comparison parameters:

  • isnot 
  • contains 
  • not_contains 
  • starts_with 
  • ends_with 
  • greater_than 
  • greater_than_or_is or greater_than_or_equals
  • less_than 
  • less_than_or_is or less_than_or_equals

As you can see, [gvlogic] supports several comparison parameters that the inbuilt [gravityforms] shortcode does not.

AND/OR Logic

[gvlogic] supports AND/OR logic. This enables you to check a value against multiple other values.

To construct an AND statement use ‘&&’ and for an OR statement, you use ‘||’. For example, here’s how you would check if a field value is equal to either 3 or 4.

[gvlogic if="{Text:3}" equals="3||4"]
Your answer was either 3 or 4

Here’s how you would check if a string contained both the words “apple” and “orange”.

[gvlogic if="{Text:3}" contains="apple&&orange"]
Your answer contained both apple and orange!

Using [gvlogic] Inside a View

You can also use [gvlogic] to conditionally display content inside a View. 

To do this, first, add a Custom Content field to your View by clicking on the + Add Field button and selecting Custom Content.

An arrow pointing to the "Custom Content" field inside the GravityView View editor

Next, click on the gear icon to open the Field Settings window. You can now use the [gvlogic] shortcode inside the Custom Content text editor to conditionally display information inside your View.

The "Custom Content" text editor containing the "gv logic" shortcode

In this example, if the user (let’s call him Dave) entered the word “Marketing” into the “Work” field on our form, then his profile will state “Dave works in the Marketing department”.

Using Conditional Logic to Restrict Content

[gvlogic] is a powerful and versatile shortcode. You can also use it to show or hide content anywhere on your website. To display content based on whether a user is logged in, use the logged_in parameter, like so:

[gvlogic logged_in="true"]
Congrats! You’re logged in!
[else]
Please log in to view this content
[/gvlogic]

To use [gvlogic] on a page or post, copy and paste your code into a Gutenberg Shortcode module.

An arrow pointing to the 'Shortcode" block inside the WordPress block editor (Gutenberg)

Checking Multiple Conditions with [gvlogic2] and [gvlogic3]

If you want to evaluate multiple conditions using [gvlogic] you can do this using nested shortcodes. [gvlogic] supports three nesting levels using [gvlogic2] and [gvlogic3].

[gvlogic...]
[gvlogic2...]
[gvlogic3…]...[/gvlogic3]
[/gvlogic2]
[/gvlogic]

As you can see, the ability to nest multiple shortcodes allows you to create complex conditional logic statements.

Field Conditional Logic in GravityView

The Advanced Filtering extension for GravityView includes a feature that allows you to enable conditional logic on individual fields inside your View.

This is helpful if you want to display fields only if certain conditions are met.

To get started, edit your View and click on the gear icon next to the field where you want to use conditional logic.

The "Add Condition" button inside the Field Settings

In the Field Setting under Conditional Logic, click Add Condition. You can now add multiple conditions using the OR and AND buttons. You can also specify what to display when the condition is not met.

The "AND" and "OR" buttons for adding conditional. Underneath that is an input box for custom content

Advanced Filtering also lets you use conditional logic to filter fields that are shown in GravityView.

Other Ways to Use Conditional Logic in Gravity Forms

Did you know that conditional logic is a feature of almost every aspect of the Gravity Forms plugin? Here are some lesser-known ways to use conditional logic inside Gravity Forms.

Exporting Entries

When exporting entries from Gravity Forms, you can choose which entries to export based on conditions that you set. This is helpful if you have a large number of entries and 

Go to the export page, select your form from the dropdown menu, choose which fields to include in your export file and then scroll down to the bottom where it says “Conditional Logic”.

Click Add condition to create a new conditional statement.

The "Add condition" button

Here’s how you would only export entries where the user chose either “Americano” or “Latte” as their favorite type of coffee.

Conditional logic conditions set up to filter entries that are being exported

Importing Entries

You can also use conditional logic when importing entries into Gravity Forms using the Import Entries plugin.

During the final step of the import process, enable conditional logic under Configure Import Options. You can now filter the entries that you import based on conditions that you set.

The "Configure Import Options" with "Conditional Import" enabled

Gravity Forms Conditional Logic: Wrapping Up

Personalization and relevant content are two important aspects of running a successful website. Conditional logic is a powerful way to optimize your website forms and create highly targeted content.

In Gravity Forms, you can use conditional logic to hide or display form fields, send personalized notifications, create variable product prices, and more.

If you have GravityView, you can use the shortcode to conditionally display content on your website based on the information a user entered in their form submission.

You can use conditional logic almost anywhere inside Gravity Forms and GravityView, including form fields, notifications, confirmations, and feeds!