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.
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 Calculations In Caldera Forms
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.
Allowed Math Functions For Caldera Forms Calculation Fields
- pow (deprecated)
- acos (deprecated in Caldera Forms 1.8.5)
- asin (deprecated in Caldera Forms 1.8.5)
- atan (deprecated in Caldera Forms 1.8.5)
- atan2 (deprecated in Caldera Forms 1.8.5)
- floor (deprecated in Caldera Forms 1.8.5)
- max (deprecated in Caldera Forms 1.8.5)
- min (deprecated in Caldera Forms 1.8.5)
- random(deprecated in Caldera Forms 1.8.5)
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
Deprecated Math Functions In Caldera Forms
Please note that “deprecated” does not mean “removed”. These features are still in the plugin, we recommend that you migrate away from them.
Caldera Forms 1.8.5 deprecates support for several math functions in order to avoid using a PHP function that is deprecated in PHP 7.2. This change effects you if you are using manual calculations and your server is running PHP 7.2 or later. These functions MAY still work, but are no longer officially supported.
What Does Caldera Forms “has been deprecated in calculation fields for compatibility with PHP 7.2 or later” Error Mean?
When a form is submitted with deprecated math functions in the manual calculation one of two things happens. If the current logged in user can edit the forms, Caldera Forms shows an error notice and attempts to process the calculation. If the current user is not logged in or does not have the capability to edit the form, no error notice is shown and Caldera Forms will attempts to process the calculation.
If you see these messages when logged in and want to continue to use these functions, you have the following options:
- Use PHP 7.1 and makes no changes to your manual calculations.
- Use PHP 7.2, make no changes to your manual calculations and keep PHP error display disabled. This probably will work fine, but is not officially supported.
- Submit a pull request adding support for the function you need, with PHP 7.2 support
Notes On Manual Calculations
%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.