🎉 Celebrate with 10% OFF on All Products! Use Code: GFEX10 Or Buy Any 2+ Items for 30% OFF with Code: GFEX30!
Guides & Tutorials October 14, 2026

Gravity Forms Conditional Logic With AND / OR Groups, Dates and Patterns

GravityExtra
Gravity Forms Conditional Logic With AND / OR Groups, Dates and Patterns

Gravity Forms conditional logic is one of the reasons people choose it: show a field when a box is ticked, skip a page for returning customers, send a notification only for large orders. Then a real project arrives. “Show the discount code field when the order is at least 3 nights and the guest is from the UK or France or has booked parking and breakfast.” “Only allow the booking when the check-out date is at least a week after the check-in date.” “Send the compliance email when the applicant is under 18.” Suddenly the familiar rule box is not enough.

This guide explains where standard conditional logic stops, what people usually do about it, and how the Gravity Forms Logic & Math Pro Premium Add-on adds AND / OR rule sets, date and age rules, pattern checks, lengths and field-to-field comparisons to every conditional logic screen in Gravity Forms, checked live in the browser and again on the server.

Where Standard Conditional Logic Stops

Each conditional logic box in Gravity Forms is a flat list of rules with one switch at the top: All rules must match, or Any rule must match. That covers simple cases well. It cannot express a mix of both. “A and (B or C)” has no place to go, so people duplicate fields, add hidden helper fields, or give up on the rule.

The comparisons are also limited to is, is not, greater than, less than, contains, starts with and ends with. Common questions cannot be asked directly:

  • Dates: is the start date in the future? Is the end date at least seven days after the start date? Is the customer 18 or older today?
  • Missing text: does the email address not contain a free mail domain? Is the field empty?
  • Formats: does the postcode, VAT number or booking reference follow a pattern?
  • Lengths: is the message longer than 20 characters? Did the visitor tick more than two boxes?
  • Two fields: is the confirmation email different from the email? Is the quantity higher than the allowed maximum stored in another field?

Each of these is a frequent request in quote forms, bookings, registrations and applications. Each one usually ends up as custom code.

The Usual Workarounds and Their Costs

Custom PHP and JavaScript. A developer can hook into the conditional logic of Gravity Forms in the browser and on the server. Doing it properly means writing the same rule twice, in two languages, keeping both in step, handling every field type (date pickers, drop-down dates, checkboxes, multi selects, pricing fields), time zones for “today”, and testing that a hidden field is really ignored when the form is submitted. The next person who edits the form needs the developer again.

Hidden helper fields and calculations. Some rules can be faked with a hidden Number field that calculates a 1 or a 0 and a standard rule that reads it. It works for numbers, but not for text, patterns or dates, and the form becomes hard to read: the logic hides in formulas spread across invisible fields.

Splitting the form. Two or three slightly different forms instead of one smart form. Every later change has to be made several times and the entries end up in different places.

Logic & Math Pro Custom code Helper fields / split forms
AND inside OR (nested groups) Yes, 5 levels Yes, per project No
Dates, age, “today + 7 days” Yes Yes, per project Partly
Patterns, lengths, “does not contain” Yes Yes, per project No
Field-to-field comparisons Yes Yes, per project Numbers only
Fields, pages, buttons, notifications, confirmations, feeds All, same rule set Each one coded Fields only
Server checks the result on submission Always If written Partly
Who can change the rules later Anyone who edits the form A developer Anyone, with care

Step-by-Step: Build Your First Rule Set

A rule set is a named group of conditions. You build it once, then use it anywhere the form has conditional logic. Here is the booking example from the introduction.

Step 1: Install and turn on the conditional logic features

Install and activate the add-on and enter your licence key in Forms → Settings → Logic & Math. The Rule sets & extra comparisons switch is on by default. Existing forms do not change: until you use a rule set or one of the new comparisons, Gravity Forms behaves exactly as before.

Step 2: Create the rule set

Edit the form and open Settings → Logic & Math. Under Rule sets, click Add rule set and give it a clear name such as “Discount eligible”. A rule set starts with one group set to All of these (AND). Add the conditions:

  1. Nights — is at least — 3.
  2. Click Add group. The new group defaults to Any of these (OR). Inside it add Country is United Kingdom and Country is France.
  3. Inside the OR group, add another group (AND) with Extras contains Parking and Extras length is over 1, so two or more extras including parking also qualify.
  4. Back in the top group: Postcode is not empty.
Rule set builder in Form Settings with a top AND group, a nested OR group and a nested AND group
The rule set builder: a top AND group with a minimum number of nights, a nested OR group for the country, a nested AND group for the extras, and a postcode that must not be empty.

Choice fields show their choices in a drop-down, number rules take a number, and the builder hides comparisons that make no sense for the selected field. Save the settings.

Step 3: Use the rule set in any conditional logic

Open the field that should appear, for example Coupon code, and enable conditional logic. In the field list of the rule you now find Rule set: Discount eligible. Choose it with is — matched. The same entry is available for pages, the Next and Submit buttons, notifications, confirmations and the conditions of add-on feeds.

Gravity Forms conditional logic panel with Rule set: Discount eligible selected
A rule set chosen in the standard conditional logic panel of the form editor.

Step 4: Add date, age and comparison rules

Date rules compare a Date field with a fixed date, with today plus or minus days, weeks, months or years, or with another date field plus or minus an offset. “Check-out is on or after Check-in + 1 week” is one condition. Age rules read a date of birth: age is at least 18. “Today” always means the date in the timezone of your site, in the browser and on the server, so a visitor in another country sees the same result your server stores.

For simple cases you do not even need a rule set: the most useful comparisons are added to the standard rules too, such as does not contain, matches pattern, is empty, length is over and, for Date fields, is before, is after and age is under.

Booking form where the coupon code field appears once the rule set matches
The booking form on the page: with two nights the stay is below the minimum, so the rule set does not match and the coupon field stays hidden. It appears as soon as the conditions are met, and the server repeats the check on submission.

Advanced Tips From Real Projects

  • One rule set, many places. Build “VIP customer” once and use it for a field, a confirmation, an extra notification to the sales team and the condition of a CRM feed. Change the rule set and every place follows.
  • Compare fields. Show a warning when Confirm email is not Email, or when Quantity is greater than Maximum allowed, a value you can set with a default or a calculation.
  • Patterns without risk. “Matches pattern” accepts the common building blocks (letters, digits, classes like [A-Z], repeats, groups and alternatives) and refuses constructions that could make a page slow. Matching ignores upper and lower case.
  • Server first. A field hidden by a rule is not validated and not saved, even if someone changes the page in the browser or submits with JavaScript turned off. Required fields only apply when their rule shows them.
  • Calculated values in rules. Combine with the formula functions of the same add-on: calculate a score with if(), min() or days_between() in a hidden Number field, then compare that field in a rule set.

Smarter forms without custom code

Logic & Math Pro gives Gravity Forms AND / OR rule sets, date, pattern, length and field-to-field rules, plus formula functions for calculations. Every rule runs live and is checked again on the server.

Frequently Asked Questions

Do my existing forms change when I update?

No. Existing rules, formulas and settings are kept exactly as they are. The new features only act when you use a rule set or one of the new comparisons.

Where can I use a rule set?

Everywhere Gravity Forms shows conditional logic: fields and sections, pages, the Next and Submit buttons, notifications, confirmations and the conditions of add-on feeds such as CRM, email marketing or payment feeds.

Does it work with multi-page forms and AJAX forms?

Yes. Pages can be skipped by a rule set, Next buttons can wait for a rule set, and the server applies the same decisions on every page and on submission.

Which date formats are supported?

All Gravity Forms date fields: date picker, date fields and date drop-downs, in every date format. Typed dates can be written as YYYY-MM-DD or in the field’s own format, or relative to today, for example today+7 or today – 18 years.

What happens if JavaScript is blocked?

The server evaluates every rule when the form is submitted, so hidden fields are ignored and required fields are only enforced when they should be shown.

0
0
Your Cart
Your cart is emptyReturn to Shop
🔥 FREQUENTLY BOUGHT TOGETHER
Complete Combo & Save 40%!
ITEM IN YOUR CART
Gravity Forms Klaviyo Add-on
$39.00/yr
+
🎁 RECOMMENDED ADD-ON SAVE 40% OFF
Original Price: $39.00/yr
Bundle Special Price: $23.40/yr