Calculated Field
The Calculated Field can take the values from the form fields and meta fields and use them to perform operations.
General Settings
This settings tab includes the basic customization fields:
- FIELD LABEL — a name that appears above the field and is visible to users;
- FORM FIELD NAME — a value that is used as an ID of this field. By default, it is generated from the FIELD LABEL value, but it can be changed if needed.
- FIELD DESCRIPTION — a description displayed under the field. It can be added to explain how to complete the field.
Field Settings
A set of options that allows customizing the input of the field:
- VALUE TYPE — a value type stored in the Calculated Field. There are two options available: “as Number” and “as String”.
As Number
With the “as Number” VALUE TYPE, the Calculated Field will calculate the numeric values taken from the form fields.
These numeric values can be set in the settings of the needed field. Some of the fields have corresponding customization fields: the CALCULATE field for the Select, Radio, and Checkbox Fields, VALUE FOR CALCULATED FIELD for the Advanced Choices Field, and CALCULATED VALUE for the Switcher Field.
When this VALUE TYPE is used, the value should be put within “%” characters. The formula will look similar to this:
%first_field% + %second_field%
- DECIMAL PLACES NUMBER — the number of the digits that will be displayed to the right from the decimal point;
- DECIMALS SEPARATOR — the separator put after the decimals. By default, it is set to “.”;
- THOUSANDS SEPARATOR — the separator put after the decimals. By default, there is no separator set;
- CALCULATED VALUE PREFIX — the text that will be shown before the resulting value here;
- CALCULATED VALUE SUFFIX — the text that will be displayed after the calculated value.
Also, check more about Advanced Math Calculations.
As String
If selected, this option can concatenate string values. For example, the “as String” VALUE TYPE can be added to summarize the content completed in the form.
In this case, the set VALUE will be taken from the fields to make concatenations and not its CALCULATE value.
If one selects the “as String” option, the values should be put inside the single or double quotes. For instance, like:
‘%first_field% %second_field%’
or
‘%first_field%’ + ‘%second_field%’
With the “as String” option selected as VALUE TYPE, no additional settings are displayed. However, there is a common customization field left for both “as Number” and “as String” VALUE TYPES:
- Hidden — a toggle that can be activated to make the current field invisible to users.
Style Settings
To open the style settings, one should press the “brush” button.
With the Style tab, the following settings can be customized:
How to Perform Calculation and Concatenation
To perform calculations, one should put the formula in the Calculated Field.
As Number
If the “as Number” FIELD TYPE is selected, the following types of values can be used in the formula:
- Static numbers — those could be either whole or fraction numbers;
- Form field value — to get the value, the macro code %field_name% should be used, where “field_name” is the title you put to the FORM FIELD NAME bar;
- Meta field value — the value will be taken from the meta field that is attached to the post where you have placed the form. To get the value, use the macro code %META::field_name%, where “field_name” is the name of the field.
Also, once the “wrench” icon above the Calculated Field is clicked, a list of macros is available. There, the form field macros and extra macros, including date operations, can be found.
You can do all sorts of mathematical operations with those values. Just type the formula into the Calculated Field text area. For example, let’s take a close look at the formula:
%quantity% * %META::price% + 2
This means that the field will take the value from the “quantity” form field, multiply it by the value of the “price” meta field, and add 2 to it.
In the Calculated Field formula, one can also add conditions for which the ternary operators can be used. More information can be checked in the How to Use Conditional Formulas in the Calculated Field tutorial.
Despite the fact that the formula is put into the field’s text area during editing, the users will see only the result of the calculations. The features of the Field tab allow customizing the look of that result:
As String
If the “as String” FIELD TYPE is selected, the fields from the current form can be concatenated.
For instance, two Text Fields can be concatenated with the following formula:
‘%first_name%’ + ‘%last_name%’
where “first_name’” and “last_name” are the FORM FIELD NAMES of the needed fields.
Or, one can add a custom text before or after the values. For instance, the form includes two fields: Text Field with a “your_name” FORM FIELD VALUE and Calculated Field with the following formula inside:
‘Full name: %your_name%’
With this formula, a value put inside the “Your name” Text Field on the front end will be immediately displayed after the “Full name:” string.
That’s all about the Calculated Field available with the JetFormBuilder plugin for WordPress.