Select Page

And/Or Conditional Logic for Gravity Forms


Have you ever wanted to create conditional logic that includes both and AND or conditions in your Gravity Form? You can achieve it by creating a separate conditional field for each set of conditions, but that creates a lot of extra fields. In this tip I'll show you how to do it with just a couple of extra fields.

This post may contain affiliate links. If you purchase something through one of these links, I will receive a small commission at no additional cost to you. Your trust is important to me and I only recommend products that I have tried and believe in. Read my full disclosure statement here.

Tools Used


Gravity Forms - Any License


Use Case

I originally encountered the need for creating and/or conditional logic in Gravity Forms when I was building a conference registration form. The organization had a member discount code and also wanted to give a unique code to each Board member that would provide the member discount to their personal invitees. In addition, there was an early bird discount. I set this up using the Conditional Pricing Perk from Gravity Wiz. Originally I created 28 different pricing conditions (one member discount code plus 13 Board member codes times two for the Early Bird Discount and regular pricing). That was cumbersome! So I tried to find a better way and managed to do it with only two conditions (early bird discount and any of the discount codes, or regular price and any of the discount codes) plus two extra hidden fields. Here I will walk you through that better way.


Step 1: Set up Your Fields

In this simplified example, we will be checking if your favorite number is greater than 5 and if your favorite color is one of the colors of the rainbow. So first we need a number field labeled Favorite Number, then a single line text field labeled Favorite Color.

Step 2: Check for Or Conditions

The first condition we will check is to see if the color entered is one of the colors of the rainbow. To do this, create a number field. I named mine “Rainbow Color Entered?” You want this field to produce a 1 if the answer is yes. You can do this one of two ways: on the General Tab, check Enable Calculation and then for the formula simply enter 1, or on the Advanced Tab enter a Default Value of 1.

Next go to the Advanced Tab and enable conditional logic. Choose to show the field if ANY of the following match. Then enter your conditions. In our example this looks like this:

Step 3: Add One More Field

Now it’s time to check to see if your favorite number is greater than 5 and your favorite color is one of the colors of the rainbow. But this is where Gravity Forms acknowledges a limitation: forms can’t do nested logic if the field has a default value (even if you use the enable calculation option in Step 2, it will still act as a default value). So we need to add one extra step to make this work: a field that tells us whether our field created in Step 2 produces a 1, without using conditional logic. To do that, we will create another number field. I named this one “Rainbow Color Entered” (without the question mark). Again enable calculation, but this time we will use a merge tag. Click the drop down next to Insert Merge Tag and choose the field you created in Step 2. It should look like this.

This pulls in the value of that field when it is shown based on its conditional logic. If the previous field does not pass its conditional logic test, the field will stay hidden and no value will calculate on this new field.

Note: both of these fields can be set to hidden on the Advanced Tab so that your users do not see your behind-the-scenes work.

Step 4: Put it All Together

Now that you have a field that tells you whether your “or” condition is met that does not use conditional logic, you can set up your result that pulls together the and AND or conditional logic fields. In this case I’ve created an HTML field that says “YES” if the conditions are met and stays hidden if not. On this field, enable conditional logic in the Advanced Tab and choose to show the field if ALL of these conditions match. Set the conditions to: Number Field greater than 5, and Rainbow Color Entered is 1. It should look like this.

Now you’ve created a Gravity Form that includes and/or conditional logic!

Test it out below. Note, I’ve left all fields visible so you can see the inner workings, but you can hide those fields that are just for internal use.

Submit a Question or Comment