Gravity Wiz

Magically enhanced tutorials, snippets and plugins for Gravity Forms!

  • Gravity Perks
    • Gravity Perks
    • Tutorials & Snippets
    • About
  • Support
    • Documentation
    • Support
    • Account

Gravity Forms Advanced Calculations

Perform advanced calculations with mathematical functions, conditionals, and a powerful formula editor.

This plugin is part of Gravity Perks, a suite of 41+ essential Gravity Forms addons with support you can count on.

  • View All Perks
  • Buy Gravity Perks

What does it do?

Advanced Calculations completely revamps calculations in Gravity Forms. Not only does it empower you with advanced mathematical functions and conditionals, it improves the formula editing experience with a powerful new editor, complete with syntax highlighting, autocompletion, shorthand field references, and so much more!

With Advanced Calculations you can create:

  • Mortgage calculators
  • Advanced calculated products
  • Auto loan calculators
  • Investment/Retirement calculators
  • BMI calculators
  • And many more!

Features

  • Heaps of mathematical functions.
    Spreadsheet style math directly in your form.
  • Conditional statements.
    Specify multiple formulas in the same field; use the right one based on your conditions.
  • Formula shorthand.
    Simplify your formulas with our field reference shorthand. No more cumbersome merge tags!
  • Syntax highlighting.
    Clarify your complex formulas and spot issues quickly with automatic syntax highlighting.
  • Secure, tamperproof calculations.
    All calculations are recalculated on submission for accuracy and security.
  • Seamless integration.
    Automatically enhances all calculation-enabled fields like Number and Calculated Product fields.
  • Automatic updates.
    Get updates and the latest features right in your dashboard.
  • Legendary support.
    We’re here to help! And we mean it.

Documentation

  1. How do I enable this functionality?
  2. Feature Details
    1. Merge Tag Shorthand
    2. Conditional Statements
      1. if/else
      2. if/elseif/else
    3. Syntax Highlighting
    4. Tooltips
    5. Functions
      1. Absolute Value – abs
      2. Average – average
      3. Ceiling – ceil
      4. Exponential – exp
      5. Floor – floor
      6. Future Value – fv
      7. Natural Logarithm – ln
      8. Logarithm – log
      9. Maximum – max
      10. Minimum – min
      11. Pi – pi
      12. Round – round
      13. Square Root – sqrt
  3. Hooks

How do I enable this functionality?

After installing and activating Gravity Forms Advanced Calculations,

Add a Number field to your form.
Check Enable Calculation.
Insert advanced calculations into form. Use the Formula Cheatsheet for a primer on calculations.

Feature Details

Merge Tag Shorthand

The true power of calculations with Gravity Forms comes from being able to reference other fields to create calculations from what users have entered. Gravity Forms uses merge tags to reference fields. Merge tags are referenced using the field ID, with or without the descriptor, such as {Field A:1} or {:1}.

Gravity Forms Advanced Calculations adds shorthand for fields to clean up your calculations and make it easier to keep track of everything. The shorthand for the same field shown above is written as F1.

Shorthand offers more readable calculations, especially for complicated functions.

Conditional Statements

Advanced Calculations supports conditional statements such as if/else and if/elseif/else. Use these statements to evaluate calculations based on field values.

if/else

if( F1 > 1.25 && F1 < 5.5 ):
	F1 * 50
else:
	0
endif;

if/elseif/else

if( F1 < 5.5 ):
	F1 * 50
elseif( F1 >= 10 ):
	F1 * 25
else:
	0
endif;

You may use as many elseif statements as needed. You are not limited to one.
Supported Operators

The following comparison operators are supported:

  • == Equal to
  • != Not equal to
  • > Greater than
  • < Less than
  • >= Greater than or equal to
  • <= Less than or equal to
Multiple Expressions

Conditional statements support multiple expressions within a single condition via the the && (and) or the || (or) operators.

To require both expressions to be true for the condition to match, you would use the && operator. In this example, the condition will only be true if Field #1 is greater than 5 and less than 10.

if ( F1 > 5 && F1 < 10 ):

If you would like your condition to match if any of the conditions are true, you would use the || operator. In this example, the condition will return true if Field #1 is greater than 5 or if Field #2 is greater than 5.

if ( F1 > 5 || F2 > 5 ):

While these examples are simple, this functionality is quite robust and can handle conditions that contain expressions with both && and || operators.

Syntax Highlighting

Advanced Calculations adds syntax highlighting and autocompletion to the calculation text area. Syntax highlighting drastically improves the readability of calculations, especially complicated ones that use conditional statements and functions.

Autocompletion aids you when inputting a function or conditional statement. When you start typing any supported function, the editor will suggest a completion. Click the suggested function (or hit return) to insert the full function with placeholder values.

The editor also automatically closes parentheses and merge tag braces. Say goodbye to invalid formulas because of an errant parenthesis!

Tooltips

When hovering over shorthand field variables and merge tag field variables with no descriptor in the formula editor, you will see a tooltip displaying the field’s label.

Functions

Advanced Calculations adds support for common functions to both save you time and effort and provide more accurate results.

Absolute Value – abs

Returns the absolute value of a number.

Show Details

Sample Usage

abs( -78 )
abs( F1 )

Syntax

abs( value )

  • value – The value or field of which to return the absolute value.
Example

In the below example, the retuned value is 14.

abs( -14 )

Average – average

Returns the average value of the arguments given.

Show Details

Sample Usage

average( F1, F2, 26 )
average( 1, 2, 3, 4, F1 )

Syntax

average( value1, [value2, ...] )

  • value1 – The first value or field to evaluate when calculating the average value.
  • value2, ... (optional) – Additional values or fields to evaluate when calculating the average value.
Example

In the below example, the returned value is 35.

average( 12, 58, 35 )

Ceiling – ceil

Rounds a number up to the next largest integer.

Show Details

Sample Usage

ceil( 25.4 )
ceil( F1 )

Syntax

ceil( value )

  • value – The value to round up to the nearest integer.
Example

In the below example, the retuned value is 36.

ceil( 35.8 )

Exponential – exp

Returns e^x, where e is Euler’s number (~2.718) and x is the provided value.

Show Details

Sample Usage

exp( 25.4 )
exp( F1 )

Syntax

exp( value )

  • value – The exponent to raise e to.
Example

In the below example, the retuned value is 148.4131591025766.

exp( 5 )

Floor – floor

Rounds a number down to the nearest integer.

Show Details

Sample Usage

floor( 75.763 )
floor( F3 )

Syntax

floor( value )

  • value – The value to round down to the nearest integer.
Example

In the below example, the retuned value is 323.

floor( 323.78 )

Future Value – fv

fv calculates the future value of an investment based on constant-amount periodic payments and a constant interest rate.

Show Details

Sample Usage

fv( F1, F2/12, F3, 10000, 1 )
fv( 0.05, 10, F1, F2 )

Syntax

fv( rate, numberOfPeriods, paymentAmount, presentValue, [endOrBeginning] )

  • rate – The annualized rate of interest.
  • numberOfPeriods – The number of payments to be made.
  • paymentAmount – The amount per period to be paid.
  • presentValue – The current value of the investment.
  • [endOrBeginning] – (optional – 0 by default) – Whether payments are due at the end (0) or beginning (1) of each period.
Units must be consistent for rate, number_of_periods, and payment_amount. For example, on a 60 month car loan this is paid monthly, the rate should be divided by 12 and the numberOfPeriods is 60. If the same loan was instead paid quarterly, the rate should be divided by 4 and the numberOfPeriods is 20.
Example

In the below example, the retuned value is 0.023.

fv( 0.0311, 60, 450, -25000, 0 )

By default fv calculates a loan. To use it to calculate a growing investment, add a minus before the formula. For example:

-( fv( 0.08, 5, 300, 2500 ) )

Natural Logarithm – ln

ln returns the logarithm of a number, base e. e is Euler’s number (~2.718).

Show Details

Sample Usage

ln( 23 )
ln( F4 )

Syntax

ln( value )

  • value – The value to calculate the logarithm, base e. value must be positive.
Example

In the below example, the retuned value is 6.19644412779452.

ln( 491 )

Logarithm – log

log returns the logarithm of a number, base 10.

Show Details

Sample Usage

log( 7 )
log( F2 )

Syntax

log( value )

  • value – The value to calculate the logarithm, base 10. value must be positive.
Example

In the below example, the retuned value is 1.6901960800285136.

log( 49 )

Maximum – max

max returns the largest value in the list of arguments.

Show Details

Sample Usage

max( F1, F4, 67 )
max( 108, F7 )

Syntax

max( value1, [value2, ...] )

  • value – The first value or field to evaluate when calculating the maximum value.
  • [value2, ...] – (optional) – Additional values or fields to evaluate when calculating the maximum value.
Example

In the below example, the retuned value is 49.

max( 36, 49 )

Minimum – min

min returns the smallest value in the list of arguments.

Show Details

Sample Usage

min( F3, 56, F8 )
min( 3, F1 )

Syntax

min( value1, [value2, ...] )

  • value – The first value or field to evaluate when calculating the minimum value.
  • [value2, ...] – (optional) – Additional values or fields to evaluate when calculating the minimum value.
Example

In the below example, the retuned value is 6.

min( 18, 6 )

Pi – pi

pi returns the value of pi to 20 decimal places.

Show Details

Sample Usage

pi()

Syntax

pi()

Example

In the below example, the retuned value is 3.14159265358979323846.

pi()

Round – round

round rounds a number to the nearest integer.

Show Details

Sample Usage

round( 12.7 )
round( F2 )

Syntax

round( value )

  • value – The value to round to the nearest integer.
Example

In the below example, the retuned value is 9.

round( 8.68 )

Square Root – sqrt

sqrt returns the square root of a number.

Show Details

Sample Usage

sqrt( F12 )
sqrt( 72 )

Syntax

sqrt( value )

  • value – The number to calculate the square root.
Example

In the below example, the retuned value is 12.

sqrt( 144 )

Hooks

  • gpac_should_clean_merge_tag_value (JS)
Gravity Forms has hundreds of hooks. Check out our Gravity Forms Hook Reference for the most thorough guide to Gravity Forms’ many actions and filters.

Perk Deets

  • Version 1.0.6
  • Updated August 9, 2022
  • Released March 28, 2022
  • View Changelog

Changelog

1.0.6

  • Fixed issue with modulo (%) operator not working correctly after submission.

1.0.5

  • Fixed issue where shorthands in formulas would not work as expected if multiple formulas used the same shorthand field variable.

1.0.4

  • Updated the priority at which we process calculations to allow other plugins to modify the formula first.

1.0.3

  • Fixed issue where shorthand variables would stop working if Populate Anything refreshed any fields used in the formula.
  • Fixed issue where shorthand variables could incorrectly replaced by partial matches. As an example, F43 could be replaced with the value of F4 if it was processed first.

1.0.2

  • Added new gpac_should_clean_merge_tag_value JavaScript filter.

1.0.1

  • Fixed issue where exponents did not support raising a number by a power containing a function.
  • Fixed an issue where exponent results between frontend and after submission could be inconsistent when parentheses and functions are used.
  • Added internationalization to strings in Advanced Calculations so they can be translated.

1.0

  • Added new pi() function that returns π to a precision of 20 decimal places.
  • Fixed issue where the Formula Cheatsheet link was not present in Gravity Forms 2.4. Additionally, the "Validate Formula" button now works as expected with Gravity Forms 2.4.
  • Added support for conditionals with multiple conditions such as if ( ({Number C:5} &lt; -15) || {Number C:5} &gt; 10 ).
  • Added support for field variables with modifiers such as {Nested Form A:4:total}

1.0-beta-1.0

  • Added syntax highlighting/validation support for Date Time Calculator's merge tags such as {weekdays:} and {weekendDays:}.
  • Updated cheat sheet.
  • Added spaces inside parentheses for function/conditional completions and in the cheatsheet.
  • Added a "Formula Cheatsheet" below the formula editor that opens a modal containing information about how to write the formulas.
  • Added support for shorthand field variables in formulas (e.g. F1 for field 1 and F5.5 for input 5.5)
  • Added new editor to the Calculation Formula field setting that can handle validation and syntax highlighting.
  • Added average() function.
  • Added FV (future value) function. Signature: FV(rate, numberOfPeriods, paymentAmount, presentValue, endOrBeginning)
  • Fixed issue where wrapping function calls in parentheses preceding by a negative symbol would not work.
  • Added support for using exponents/functions inside conditionals
  • Fixed issue where conditionals couldn't contain equal signs after improving security around eval().
  • Improved support for nested function calls.
  • Fixed issue where addition inside parentheses/functions was not being processed.
  • Updated existing log() function which was a natural log to be ln(). log() is now base 10. Additionally, exp() is now an available function.
  • Added "Update URI" to plugin header to improve security.

1.0-alpha-1.0

  • Fixed issue where passing parentheses into function parameters or values that are replaced with values containing parentheses would not calculate correctly.
  • Added more functions: sqrt(), round(), ceil(), floor()
  • Fixed decimal numbers breaking formulas.
  • Improved functions to be case-insensitive.

0.10.1

  • Fixed issue where Enhanced Calculations would not work if there are multiple forms on the same page using calculations.
  • Added support for elseif's in conditionals.
  • Added support for min and max functions. Example: max({Number A:1}, {Number B:2}, 5*50)
  • Fixed issue where backend calculations would not match frontend calculations in some cases.
  • Fixed issues with currency values in conditions.
  • Fixed issue where empty fields could cause errors when evaluating formulas.

All Perks

  • GF Address Autocomplete
  • GF Advanced Calculations
  • GF Auto List Field
  • GF Auto Login
  • GF Better User Activation
  • GF Blocklist
  • GF Conditional Logic Dates
  • GF Conditional Pricing
  • GF Copy Cat
  • GF Date Time Calculator
  • GF Disable Entry Creation
  • GF Easy Passthrough
  • GF eCommerce Fields
  • GF Email Users
  • GF Entry Blocks
  • GF Expand Textareas
  • GF File Upload Pro
  • GF Inventory
  • GF Limit Checkboxes
  • GF Limit Choices
  • GF Limit Dates
  • GF Limit Submissions
  • GF Live Preview
  • GF Media Library
  • GF Multi-Page Navigation
  • GF Nested Forms
  • GF Notification Scheduler
  • GF Page Transitions
  • GF Pay Per Word
  • GF PayPal One-time Fee
  • GF Placeholder
  • GF Populate Anything
  • GF Post Content Merge Tags
  • GF Preview Submission
  • GF Price Range
  • GF QR Code
  • GF Randomizer
  • GF Read Only
  • GF Reload Form
  • GF Terms Of Service
  • GF Unique ID
  • GF Word Count

Copyright © 2022 · Powered by WordPress · Gravity Wiz LLC

  • Support
  • Affiliates
  • About
  • Sitemap
  • Terms & Conditions of Use
  • Privacy Policy
  • Cookies Policy

Get access to hundreds of Gravity Forms plugins for free!

Enter your email and receive a list of our most popular free snippets and plugins for Gravity Forms.

  • Gravity Perks
    ▼
    • Gravity Perks
    • Tutorials & Snippets
    • About
  • Support
    ▼
    • Documentation
    • Support
    • Account