Adding a formula to a Gravity Forms form

14,371

Solution 1

Gravity Forms confirmed that it is not currently possible to include if/and/else statements in their formulas (Gravity Forms v1.6.4).

Hope to see this in a future version!

Solution 2

Not sure if you already know this but for numeric calculations I've found I can partially get round the problem using Conditional Logic and Default Values. I'm using Gravity Forms 1.7.2.

The basic idea is to add a new Number field to your form which uses Conditional Logic so it is displayed when your condition is true and not displayed otherwise. Make sure to give the field a Default Value which is meaningful for your application.

Now if you include your new Number field in a calculation it will take the value 0 if the field is hidden (your condition is false) and the Default Value you chose if the field is displayed (your condition is true).

Example:

Field 0: Label: "Cost Of Hamburger"; Type: Number; Default Value: 10

Field 1: Label: "Extra Cheese?"; Type: Radio Buttons; Choices "Yes", "No"

Field 2: Label: "Cost of Extra Cheese"; Type: Number; Conditional Logic: Show This Field If Extra Cheese is "Yes"; Default Value: 2.50

Field 3: Label: "Total Cost"; Type: Number; Enable Calculation: {Cost of Hamburger} + {Cost of Extra Cheese}

You should find that the Total Cost field shows 10 if Extra Cheese is "No", but when you change Extra Cheese to "Yes" Total Cost will change to 12.50.

Hope this helps someone!

Solution 3

You can accomplish this through a series of fields. Let's say your answer is 840

  1. Add a field: Calculate the actual total and divide by 100. (Result 8.4)
  2. Add a field: Calculate the actual total and divide by 100 - then ROUND it to 0 decimal place. (Result 8)
  3. Add a field: Calculate the difference (0.4)
  4. Add a field: Add 1 (number 1) with conditional logic that if the difference > 0, then it's there. (Result 1)
  5. Add a total (Result of 2 plus Result of 4) * 100. Result: 900.
Share:
14,371
Caroline Elisa
Author by

Caroline Elisa

Updated on June 08, 2022

Comments

  • Caroline Elisa
    Caroline Elisa almost 2 years

    Gravity forms allows for basic field calculations using merge tags, such as {Field 1:1} * {Field 2:2}, but I would like to use if/and/else statements to set a field value such as:

    if (and ({Field 1:1} = 200,{Field 2:2} = 1), 100, if (and ({Field 1:1} = 200,{Field 2:2} = 2), 150, if (and ({Field 1:1} = 200,{Field 2:2} > 2), 200, 0)))

    or in other words:

    if (field_1 = 200) { if (field_2 = 1) { field_3 = 100 } else if (field_2 = 2) { field_3 = 150 } else { field_3 = 200 }

    Hoping someone can give me some idea of how to include this kind of calculation in Gravity Forms.

    FYI: Here is the form I am working on. I hope to use formulas instead of 21 different variations of the 'Course 1 week 1 topup' conditional field which appears only when course 1 and week 1 are selected.

    Thanks!

  • Daniele B
    Daniele B almost 9 years
    Mick this is excellent, but then the number fields with the prices will be editable by the user, how to prevent that?