Calculation Fields

Caldera Forms Banner

Caldera Forms calculation fields are mainly used for calculating and displaying total prices based on form input. Calculation fields have two modes: visual and manual. The visual editor is a simple way to add, subtract, multiply and divide the values of fields or variables.

The visual editor is easy to use and works for most of the time. Most of this documentation concerns manual formulas, since they are an advanced feature.

Rounding Calculations

Settings in a Caldera Forms calculation field related to roundingBy default, calculation fields do not round off the calculated value. If you need mathematical precision, that’s good. If you’re collecting money, that’s sub-optimal.

The Money Format option, when checked will round off the calculated value to only show two decimal places. In addition, the calculated value will always have two decimal places. If you are using a calculation field to provide the total amount to be charged by a Caldera Forms payment processor, then you should check the money format option.

When Money Format is checked you will see two additional settings:

Thousand Separator: Enter the character that will be shown every three places in the value.

Decimal Separator: Enter the character to divide the whole number and decimal places.

Using Manual Mode

In manual mode, you can create complex formulas. You can create your calculations using any math function listed below. Field or variable values can be used via magic tags. For example to add the value of a field with the slug “field_1” to the sine of the field with the slug %field_2% you would use, for your manual calculation you would use %field_1% + sin( %field_2% ).

For security reasons, calculation fields are processed both in the browser and then again on the server during submission. The calculations are processed in the browser so their results can be updated live providing a great experience to your customers. The calculations are re-run during submission to prevent tampering.

For this reason, it is important that when using magic tags based on GET variables to not use them directly in the calculation. Instead, create a hidden field, set its value with the magic tag and then use that hidden field in the calculation.

Using Magic Tags In Caldera Forms

 

Allowed Math Functions For Caldera Forms Calculation Fields

  • pow
  • abs
  • acos
  • asin
  • atan
  • atan2
  • ciel
  • cos
  • exp
  • floor
  • log
  • max
  • min
  • random
  • round
  • sin
  • sqrt
  • tan

All of these functions are used in the browser as methods of the global Math object. Caldera Forms automatically adds Math.. To use Math.pow() you would use pow(%field_slug%) not Math.pow(%field_slug%), which would create a JavaScript Error.

Notes On Manual Calculations

Manual calculations are using JavaScript math functions. You should not use Math. In front of your functions or you will create an error. For example, to multiply the value of a field with the slug field_1 by the value of a field with the slug field_2 raised to the second power, you would use %field_1% * pow(%field_2%, 2 ).

Also keep in mind that you should not end your formula with a semicolon. You also can not use any variables or call other types of functions.

If your Caldera Forms calculation field does not work or does not display anything, please check your JavaScript console. Using these manual calculation fields wrong will create a JavaScript error, that will break your form, use the console to identify these errors.