Gravity Forms Advanced Conditional Shortcode

Display conditional Gravity Forms content anywhere shortcodes are supported with multiple conditions.

Overview

Did you know that Gravity Forms provides a shortcode to display different content based on what the user has entered in their submission? If not, check out our Gravity Forms Conditional Shortcode article for an overview how it works. Afterwards, hop back into this article to learn how to get the most out of it.

Just getting started with Gravity Forms Shortcodes? Check out our comprehensive guide.

One limitation of the built-in shortcode is that it only allows for a single condition. If you wanted to display content based on the values from multiple fields, until recently the only solution has been to use multiple shortcodes. At best, it’s a clunky solution, and at worst it’s a headache to troubleshoot.

To solve this problem, we built a plugin that adds support for including multiple conditions in a single shortcode. This will not only save you time, but it gives you the freedom to display content using complex conditional logic in Confirmations, Notifications, and anywhere else shortcodes are supported.

  1. Overview
  2. Using the Plugin
    1. Prerequisites
    2. Using the Shortcode
    3. Parameters
  3. Taking It Further

Using the Plugin

Prerequisites

Confirm that you have Gravity Forms installed and activated and that you’ve installed and activated the plugin.

Using the Shortcode

Gravity Forms Advanced Conditional Shortcode adds additional parameters to the [gravityforms] shortcode to allow for multiple conditions. Let’s step through an example scenario.

Say you run a store that sells accessories for cars and trucks, and you want to offer specific products to your customers on the Confirmation page based on choices they make in the form.

Using Advanced Conditional Shortcodes, you can target specific combinations to display content.

In this example, if a customer selects both “SUV” and “Off-road” they’ll see a message about off-road accessories. Any other combination only displays the default message.

Parameters

Advanced Conditional Shortcodes supports all of the parameters in the vanilla Gravity Forms Conditional Shortcode with the addition of the following.

  • relation (string) (required)

    The type of relation between the different conditions. Possible relations include:
    • all
    • any
  • value (string) (required)

    Specify the merge tag to be evaluated by the operator and the compare.

    You can find a full list of form-specific merge tags while editing a Notification or Confirmation under the merge tag button:
  • operator (string) (required)

    Enter the operator to be used to test the content of the merge tag with the value you specify. Similar to the condition parameter in the vanilla shortcode, but specific to Advanced Conditionals. Possible conditions include:
    • isnot
    • is
    • greater_than
    • less_than
    • contains
    • starts_with
    • ends_with
  • compare (string) (required)

    The value that will be compared against the value based on the operator.

Unlimited value, operator, and compare parameters can be added to the conditional shortcode. Simply add a number to the end of each of the parameters to group them together. For example, a second group looks like this:

value2="{:2}" operator2="is" compare2="Off-road"

Taking It Further

Same as the standard Conditional Shortcode, the Advanced Conditional Shortcode will work in HTML fields when using Gravity Forms Preview Submission. The same is true for using Advanced Conditional Shortcodes in post content via GF Post Content Merge Tags. More info in our Gravity Forms Conditional Merge Tags article.

Comments

  1. Gbenga Michael
    Gbenga Michael March 20, 2024 at 11:41 am

    Hello; i have the following conditional shortcode in my confirmation box;

    [gravityforms action="conditional" merge_tag="{:1.3}" condition="isnot" value="{:16}"] [gravityform action="conditional" merge_tag="{:1.6}" condition="isnot" value="{:15}"] [gravityform action="conditional" merge_tag="{:7:d-M-y}" condition="isnot" value="{BvnDoB:17}"]

    Credentials Do Not Match! Please ensure your first and last name, as well as your Date of Birth, match with the information provided in your BVN.

    [/gravityform][/gravityform][/gravityforms]

    I am getting this as the response;

    Credentials Do Not Match! Please ensure your first and last name, as well as your Date of Birth, match with the information provided in your BVN. [/gravityform] Invalid Credentials! Your first and last name does not match with the one on your BVN. [/gravityform] [/gravityform] [/gravityform]

    Why is it repeating the closing merge tags again? What am i doing wrong please?

    Reply
    1. Scott Ryer
      Scott Ryer Staff March 22, 2024 at 11:47 am

      Hi Gbenga,

      Your shortcode syntax needs some adjustments.

      The conditional shortcode is [gravityforms]. You have shortcodes that are written as [gravityform]. Update those to [gravityforms] and you should be good to go.

    1. Samuel Bassah
      Samuel Bassah Staff August 10, 2023 at 8:24 am

      Hi Denes,

      Glad the code was useful to you. I will forward your feedback to our developers to look into it. Thanks

      Best,

  2. K
    K March 17, 2023 at 3:39 pm

    Hi, we are looking to get the title to show in the notifications only if one of fields was selected. It is not working, no title is showing. Thanks

    [gravityforms action="conditional" relation="any" value="{:36}" operator="is" compare="Brochure" value2="{:37}" operator2="is" compare2="Pamphlet" value3="{:38}" operator3="is" compare3="Flyer"]This is the title[/gravityforms]

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff March 20, 2023 at 3:24 am

      Hi K,

      The conditional shortcode you have is correct. The tutorial has a code/plugin to add to your website to get the conditional shortcode to work. Can you confirm if you’ve already added the snippet or installed the plugin on your website?

      Best,

  3. Chris Bradley
    Chris Bradley August 26, 2022 at 2:00 pm

    Can this be used to show a form if the logged-in user does not have an entry for the form? We are using the Gravity View plugin to show a user profile UI that links to the Gravity Form entry the user created. If the user does not have an entry, we would like to show the Gravity Form.

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff August 27, 2022 at 6:51 am

      Hi Chris,

      This is an interesting use case, but I doubt the shortcode would work for that. I’ll forward your request to our product manager. Please expect an additional reply on this soon.

      Best,

  4. Ian Clarke
    Ian Clarke July 19, 2021 at 4:34 am

    Can this be used as a Conditional Logic test to compare the value of two fields

    so if Field A = Field B display/hide Field C

    Reply
    1. Samuel Bassah
      Samuel Bassah Staff July 19, 2021 at 9:38 am

      Hi Ian,

      You can use this snippet to compare values, like if Field A = Field B displays Field C, but it works with Conditional shortcodes and not Conditional logic. If you have an active Gravity Perks license, you can get in touch with us via our support form with your account email, so we see how best we can assist you with a solution that will work for the field to field conditional logic.

      Best,

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Download Plugin

Gravity Forms Advanced Conditional Shortcode

This field is for validation purposes and should be left unchanged.