🎉 Celebrate with 10% OFF on All Products! Use Code: GFEX10 Or Buy Any 2+ Items for 30% OFF with Code: GFEX30!

Gravity Forms Logic & Math Pro Premium Add-on Setup Guide

Updated 11 min read Gravity Forms Fields & Inputs
On this page
  1. Video walkthrough
  2. Step 1: Install and Activate Your License
  3. Step 2: Choose Which Functions Are Available
  4. Step 3: Write a Formula
  5. Math and Logic Functions
  6. Date Functions
  7. Choice Count and Sum
  8. How Results Are Calculated
  9. Conditional Logic: Rule Sets (new in 1.1)
  10. Create a rule set
  11. Use a rule set
  12. Comparisons
  13. Extra comparisons in standard rules
  14. Patterns
  15. How rules are checked
  16. Switching it off
  17. Limits and What Is Not Included
  18. Troubleshooting & FAQ
  19. Validate Formula says my formula is invalid.
  20. The result stays empty or shows 0.
  21. The age or days look one day off.
  22. Do my existing formulas change?
  23. Can a visitor change the calculated value?
  24. Resource Hub
  25. Visitor rules: logged in, user role and user meta
  26. Where to find them
  27. Comparisons
  28. Allowing user meta keys
  29. How it is checked
  30. Page caching

Video walkthrough

Gravity Forms Calculations with if(), Dates & Discounts (Nights, Tiers, Fees)
Watch: add if(), date maths and discounts to Gravity Forms calculations Watch on YouTube

Gravity Forms calculation formulas understand numbers, merge tags, + – * / and brackets. Anything that needs a decision, a minimum or maximum, a date difference or a count of ticked boxes cannot be written, and Gravity Forms returns 0. The Gravity Forms Logic & Math Pro Premium Add-on adds functions you type straight into the formula box of a Number field with Enable Calculation or a Calculated product field.

Results update live while the visitor fills in the form and are calculated again on the server when the form is submitted, so the stored value always matches the formula. This guide covers installation, the settings, each group of functions, the form editor helper, rule sets and the extra comparisons for conditional logic, the limits and troubleshooting.

System Requirements & Prerequisites

  • WordPress: Version 6.5 or higher
  • PHP: Version 7.4 or higher
  • Gravity Forms: Version 2.9.4 or higher
  • Fields: A Number field with Enable Calculation, or a Product field with the Calculation field type
  • GravityExtra license: The add-on installed, activated and licensed with an active GravityExtra license key

Step 1: Install and Activate Your License

  1. In WordPress go to Plugins → Add New → Upload Plugin, upload the add-on ZIP file and click Activate.
  2. Go to Forms → Settings → Logic & Math, enter your key in the Gravity Extra License section and click Activate License.
  3. Reload the page. The Formula functions section appears. The functions work only while the license is active.

Step 2: Choose Which Functions Are Available

The Formula functions section has three switches, all on by default: Math & logic functions, Date functions and Choice count & sum. Formulas that only use + – * / and brackets keep working exactly as before, whatever you choose here. When you switch a group off, formulas that use it are handed back to Gravity Forms unchanged, which means they return 0.

Each form also has a switch. Open the form, go to Settings → Logic & Math and use Use formula functions on this form. It is on by default; when it is off, the form’s formulas work exactly as standard Gravity Forms formulas and the add-on loads nothing on that form.

Step 3: Write a Formula

  1. Edit a form and add a Number field (or a Product field with the Calculation field type).
  2. Tick Enable Calculation and type the formula. Insert fields with the merge tag drop-down as usual.
  3. Use the Insert function drop-down above the formula box to add a function, and Insert date or choice field to add a Date, Checkboxes or Multi Select field.
  4. Click Validate Formula. Formulas with an unknown function, the wrong number of values or a syntax error are reported as invalid.
  5. Pick the Rounding you want and save the form.
Calculation options in the form editor with the formula box, the Insert function and Insert date or choice field drop-downs and the Function reference link
The helper above the formula box in the form editor.

Function reference opens a short list of every function with a one-line description, so you do not need to leave the editor.

Math and Logic Functions

Comparisons can be used anywhere in a formula: = (or ==), != (or <>), >, <, >= and <=. A comparison returns 1 when it is true and 0 when it is false, and any value other than 0 counts as true. Function names are not case-sensitive.

Function Result
if(condition, a, b) a when the condition is true, otherwise b
and(a, b, ...) 1 when every value is true
or(a, b, ...) 1 when at least one value is true
not(a) 1 when a is 0
min(...) / max(...) Smallest / largest value
sum(...) Adds up the values
round(x, decimals) Rounds to 0–10 decimals, halves away from zero
floor(x) / ceil(x) Rounds down / up to a whole number
abs(x) Value without its minus sign
pow(x, y) x to the power of y
sqrt(x) Square root, 0 for negative values
mod(a, b) Remainder of a divided by b

Example: 10% off when more than 10 hours are booked: if({Hours:1} > 10, {Hours:1} * {Rate:2} * 0.9, {Hours:1} * {Rate:2}). A minimum charge of 2 hours and a maximum of 40: min(max({Hours:1}, 2), 40).

Project quote form on the Orbital theme showing a 10% discounted subtotal, billable hours, a score and a calculated package price
Live results on the front end (Orbital theme).

Date Functions

A Date field inside a formula becomes a day number, so you can subtract two dates or add days. An empty, incomplete or invalid date counts as 0, and the date functions return 0 when a date they need is missing. All three Date field input types (date picker, date field and date drop-down) and all date formats are supported.

Function Result
today() Today’s date in the site’s timezone (Settings → General)
days_between(start, end) Days from start to end, negative when end is earlier
age(date) Full years from the date until today, 0 for a future date
weekday(date) 1 = Monday … 7 = Sunday

Example: a room total of 120 per night that is never negative: if(days_between({Check-in:1}, {Check-out:2}) > 0, days_between({Check-in:1}, {Check-out:2}) * 120, 0).

Room booking form with check-in and check-out dates, date of birth and event day, and the calculated nights, guest age, event weekday, days until the event and room total
Date functions calculating live.

Choice Count and Sum

Add the whole field (for example {Extras:7}, not {Extras:7.1}) of a Checkboxes or Multi Select field to a formula and it becomes the sum of the selected choice values. Choices whose value is not a plain number count as 0, so give each choice a numeric value under show values. count({Extras:7}) returns how many choices are selected. A field hidden by conditional logic counts as 0.

How Results Are Calculated

In the browser, the add-on hooks into the Gravity Forms calculation step, reads the current field values the same way Gravity Forms does and hands back the result, which Gravity Forms then rounds and formats as usual. When the form is submitted, Gravity Forms recalculates every calculation field on the server and the add-on evaluates the same formula there, so a value changed in the browser is never stored. Formulas are read by a built-in parser that only knows the listed functions; nothing in a formula is ever run as code. Division by zero, the square root of a negative number and results that are too large all give 0.

Conditional Logic: Rule Sets (new in 1.1)

Gravity Forms conditional logic matches All or Any of a flat list of rules. A rule set combines conditions in groups: a group is either All of these (AND) or Any of these (OR), and groups can contain further groups, up to five levels deep. You build rule sets once per form and use them in every conditional logic of that form.

Create a rule set

  1. Edit the form and open Settings → Logic & Math.
  2. Under Rule sets, click Add rule set and give it a name.
  3. Pick a field, a comparison and what to compare with (a value, another field or, for dates, today). Use Add condition and Add group to build the logic.
  4. Click Save Settings. The card shows where each rule set is used.
Rule sets in Form Settings with nested AND / OR groups, a date compared with today and a date compared with another field plus one week
Rule sets: nested groups, an age rule, dates relative to today and to another field, and field-to-field comparisons.

Use a rule set

Open the conditional logic of a field, section, page, Next button, the submit button, a notification, a confirmation or an add-on feed. In the field list of a rule choose Rule set: <name>, then is (or is not) matched.

Form editor conditional logic panel with Rule set: Discount eligible is matched
A rule set in the conditional logic panel of the form editor.
Notification conditional logic using Rule set: VIP is matched
The same rule set in a notification. Confirmations and feed conditions work the same way.

Comparisons

  • Text: is, is not, contains, does not contain, starts with, ends with, matches pattern, is empty, is not empty. Upper and lower case are ignored.
  • Number: equals, does not equal, is greater than, is at least, is less than, is at most. Values are read in the field’s number format; numbers you type use a dot for decimals.
  • Length: length is, length is over, length is under — characters, or the number of selected choices for Checkboxes and Multi Select.
  • Date: is on, is before, is after, is on or before, is on or after, is between (both ends included), age is at least, age is under (full years).
  • Compare with: a value; another field; or, for dates, today. Dates of another field and today can be shifted by days, weeks, months or years (31 January + 1 month = end of February). A typed date can be YYYY-MM-DD, the date in the field’s own format, or today, today+7, today - 2 weeks, today + 1 month, today - 18 years.
  • Several selected values (Checkboxes, Multi Select): a comparison matches when any selected value matches; “is not” and “does not contain” match when none does.

Extra comparisons in standard rules

Without a rule set, Gravity Forms’ own rules also offer does not contain, matches pattern, is empty, is not empty, is at least, is at most, length is over and length is under; for Date fields is on, is before, is after, age is at least and age is under. Choice fields offer does not contain, empty, not empty and lengths. To compare with another field, type its merge tag as the value, for example {Start date:5}.

Confirmation conditional logic: Date of birth age is under 18
An extra comparison in a confirmation rule: show this confirmation to visitors under 18.

Patterns

matches pattern accepts letters, digits, classes such as [A-Z], ^ $ . d w s, groups, alternatives and repeats, for example ^[A-Z]{1,2}d for the start of a UK postcode. Look-arounds, back-references, a repeated group that already repeats and patterns longer than 200 characters are refused when you save, so a pattern can never slow your site down. Values longer than 1,000 characters never match a pattern.

Rule set builder refusing an unsupported pattern before saving
An unsupported pattern is highlighted and the settings are not saved until it is fixed.

How rules are checked

Fields, pages and buttons update live while the visitor fills in the form. When the form is submitted, Gravity Forms checks every rule again on the server with the add-on: a field hidden by a rule is not validated and not saved, whatever the browser sends, and the same is true with JavaScript turned off. Notifications, confirmations and feeds are decided on the server only. “Today” is the date in the timezone set in Settings → General, in the browser and on the server.

Multi-page form where a rule set skipped the adult page and the Join button appears once Signature is filled
Multi-page form: page 2 was skipped by a rule set, and the submit button appears once the signature is not empty.

Switching it off

Forms → Settings → Logic & Math → Rule sets & extra comparisons. When it is off, rules that use a rule set or one of the extra comparisons never match; standard rules keep working.

Limits and What Is Not Included

  • Number and Calculated product fields only. Text, Hidden and other field types cannot use the functions yet.
  • Numbers only. There are no text functions, and date results are day counts, not formatted dates.
  • Conditional logic for showing fields, notifications and feeds is not changed by this version.
  • Formula length: up to 2,000 characters and 32 levels of nested brackets; longer formulas return 0.
  • today() in the browser uses the site timezone offset from when the page was loaded. The value saved on submission always uses the server date.

Troubleshooting & FAQ

Validate Formula says my formula is invalid.

Check the function name and the number of values (for example if() needs three), that every bracket is closed and that values are separated by commas. A function from a group that is switched off in Forms → Settings → Logic & Math is also reported as invalid.

The result stays empty or shows 0.

Check that the license is active, that Use formula functions on this form is on in the form settings, and that the group the formula uses is on. For Checkboxes, make sure the choices have numeric values.

The age or days look one day off.

The add-on uses the timezone in Settings → General. Set it to your business’s city rather than a UTC offset.

Do my existing formulas change?

No. Formulas that only use + – * / and brackets are left to Gravity Forms exactly as before.

Can a visitor change the calculated value?

No. Calculated values are recalculated on the server when the form is submitted.

Resource Hub

Visitor rules: logged in, user role and user meta

From version 1.2.0 a rule can depend on who is filling in the form. Use it to show a “Staff notes” field to editors only, a member code to logged-in members, or a sign-up box to visitors who are not logged in.

Where to find them

  • In a rule set (Form Settings → Logic & Math): click Add visitor condition, then pick Visitor: logged in status, Visitor: user role or Visitor: user meta …. Visitor conditions can be mixed with field conditions in AND / OR groups.
  • In Gravity Forms’ own conditional logic (fields, pages, the submit button, notifications, confirmations and feeds): the same three sources are listed at the end of the field list.

Comparisons

  • Logged in status: is logged in / is logged out.
  • User role: is / is not any role on your site, custom roles included. A visitor who is not logged in has no role.
  • User meta: is, is not, contains, is empty, is not empty (upper and lower case are treated the same).

Allowing user meta keys

User meta rules only work with the keys you list under Forms → Settings → Logic & Math → User meta keys for visitor rules, one per line (for example membership_level). The list is empty by default. Keys for passwords, tokens, sessions and capabilities are never accepted. If you remove a key from the list, rules that use it stop matching and the rule set shows a warning.

How it is checked

Visitor rules are worked out on the server. The page only receives “true” or “false” for each rule, never a role list or a user meta value. When the form is submitted the server checks every rule again, so a field hidden from a role is not validated or saved, whatever the browser sends. After submission, notifications, confirmations and feeds use the person who submitted the entry, so resending a notification later gives the same result.

Page caching

Because different people see different fields, pages with a form that uses visitor rules are marked “do not cache”. Most caching plugins respect this. If your host or CDN caches pages anyway, exclude the page with the form from the cache. Forms without visitor rules are cached as before.

Logic math user meta keys
Logic math visitor form guest
Logic math visitor form member
Logic math visitor rule set

Still need help?

Our support team answers tickets every day, usually within a few hours.

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