Building forms
Calculations
Totals, quotes and scores with formulas that are checked again on the server.
Add a Calculation field (Payment group) and write a formula. The result updates as the visitor answers, and the server calculates it again from the submitted answers, so a changed number in the browser cannot change a total or a payment.
Writing a formula
Refer to other fields by their field name in braces:
{rooms} * 40 + {extras}
Below the formula box, every field you can use is listed as a button that inserts its name at the cursor. The box tells you when the formula is valid, or what is wrong with it.
| Value used | What a field contributes |
|---|---|
| Number, slider, rating, scale | Its number |
| Dropdown, single choice | The choice's calculation value if set (in the choice's advanced settings), otherwise its value if it is a number |
| Multiple choice | The sum of the chosen choices' calculation values |
| Consent | 1 when ticked, 0 when not |
| Date | Use days() and age() (below) |
| Repeating group field | The values of every row, for sum(), avg(), min(), max() and count() |
Empty answers count as 0. Answers of hidden fields count as 0 unless you turn on Use values of hidden fields.
Operators
+ - * / % (remainder) ^ (power), comparisons = != < <= > >=, and and, or. Use brackets to group.
Functions
| Function | Result |
|---|---|
round(x) or round(x, 2) |
Rounded, to whole numbers or to the given decimal places. Halves round away from zero: 2.5 becomes 3 and -2.5 becomes -3 |
ceil(x), floor(x) |
Rounded up or down |
abs(x) |
Without the minus sign |
min(a, b, ...), max(a, b, ...) |
Smallest or largest |
sum(...), avg(...), count(...) |
Total, average and number of values (useful with repeating groups) |
if(condition, then, else) |
For example if({nights} >= 7, {price} * 0.9, {price}) |
clamp(x, low, high) |
x limited to a range |
days(from, to) |
Days between two dates, for example days({arrival}, {departure}) |
age(date) |
Whole years from a date to today |
len(text) |
Number of characters |
number(text) |
A number typed as text |
Showing the result
Choose number, money (with a currency), percentage or text; the number of decimal places; separators (from the site language by default); and text before and after. A calculation can also be hidden from visitors and used only in emails, entries, conditions and payments.
Taking a payment
In the form's Payment tab, set the amount to come from a calculation field. The amount charged is always the server's result. See Payments.
Limits
Formulas are calculated without running any code: there are no loops, and very long or deeply nested formulas are refused with a message. Division by zero gives an empty result rather than an error on the form.
Decimal sums are exact to the decimal places you see: 0.1 + 0.2 gives 0.3, not 0.30000000000000004. Money is charged in the currency's smallest unit (cents, or whole yen for currencies without them).
Two calculations cannot depend on each other, directly or through other fields and conditions. The form shows the loop when you publish and is not published until it is removed.