Skip to main content

Computed fields

Introduction​

A Computed field (in the Special group) holds a value worked out from other fields on the same form: a full name, an order total, an age. It updates as the visitor types. The server works it out again from the submitted answers, whatever the browser sent, and stores it like any other answer, so it appears in the submission, exports, emails, conditions and {exp:formidable:submissions}.

What it can calculate​

The field's Computation tab offers four kinds:

CalculateExampleResult
Text from other fields{first_name} {last_name}Ada Lovelace
A number{quantity} * {unit_price}47.98, shown as $47.98
The time between two datesfrom {birthday} to Today, in years34
A date moved{start_date} plus 30 days2026-11-10

Fields are named by handle, in braces. Insert field, beside the template and the expression, lists the form's other fields and puts the one you pick at the cursor, so you don't have to remember handles. The editor's Depends on list shows which fields the saved calculation reads.

Text​

Literal text and fields, in any order. An empty field takes one separator with it, so {street}, {city}, {postcode} with no city gives 1 High St, AB1 2CD, never a stray comma. Several answers from Checkboxes are joined with , .

Numbers​

A formula of numbers, fields, + - * /, parentheses and a trailing % (15% is 0.15):

({subtotal} + {shipping}) * 120%
  • A field must hold a plain number: 1234.5 or -3, not 1,234 or three. Otherwise the result is empty.
  • An empty field makes the result empty, or counts as 0 if you choose count as 0.
  • Division by zero gives an empty result.
  • sum({field}), count({field}) and average({field}) total a field in a repeating section over its rows. Empty rows are left out, and count counts the rows that have an answer. A field answered once counts as one row.
  • Results are rounded half away from zero to the decimals you choose, and displayed with your choice of thousands separator, decimal point, and text before and after ($, days). The stored answer is always the plain number, such as 1234.50, so it compares and exports cleanly.

There is no eval anywhere: the formula is checked and compiled when you save it, and saving refuses an unknown field, a syntax error, or a loop through other computed fields, naming the loop.

Dates​

The time between two dates is counted in days, weeks, months, years, hours or minutes. Months and years count complete ones, as an age does. Count both ends adds one day (1 to 3 October is 3 days). A date moved adds or subtracts days, weeks, months or years, keeping the day of the month where it can (31 January plus a month is the last day of February).

The dates can be date fields, other computed fields, Today or Now. Today and Now are the site's local date and time, so a page rendered just before midnight agrees with itself.

Showing it​

A new Computed field is hidden on the form: worked out and stored, but not shown. Turn on Show on the form to display it, read-only, where it sits in the builder. It renders as an <output> that screen readers announce as it changes, beside a hidden input carrying the plain value.

Using it​

  • Conditions can read it. A field, page or section can depend on a computed value, such as showing a guardian's name when Age is less than 18. It compares as what it produces: a number, a date or text.
  • Workflow emails include it as {field:HANDLE}.
  • Other computed fields can use it. Each is worked out after the fields it depends on, wherever they sit in the form.

When the calculation changes​

A stored answer is a record of what was true when the form was submitted. Changing the calculation doesn't rewrite old submissions on its own. Instead, the form shows a notice offering to Recalculate them, with a progress bar. You can also run Recalculate computed answers from Utilities, or, for a large form or a deploy script, use the command line:

php system/ee/eecli.php formidable:recalculate --form=order
php system/ee/eecli.php formidable:recalculate --all --dry-run

Recalculating does not change a submission's updated date or run workflows. Editing a submission in the control panel also works its computed answers out again.

Renaming a field a calculation uses changes nothing for it, because calculations refer to fields by id. The editor simply shows the new handle.