How to calculate a price right in the form
← BackAdd a field of type “Calculator” and enter the “Calculation formula” — in it you can reference other fields in curly braces.
- Add a field and select the “Calculator” type.
- In the “Calculation formula” field, write an expression. Names of other fields are inserted via buttons from the “Insert field:” row — they're substituted in curly braces:
{Print run} * {Price}. - Save. The result recalculates as soon as the visitor changes any field in the formula.
What the formula language can do:
- arithmetic
+ - * / ( ), decimals written with a comma or dot; - conditions:
If … then … ElseIf … then … Else … EndIf; - comparisons
= <> < > <= >=andCONTAINS, logicAND,OR,NOT; - functions (arguments separated by semicolons):
ROUND(x; digits),ROUNDUP,ROUNDDOWN,INT,MIN,MAX,ABS,SQRT,POWER(x; y),COUNT; - multiple choice:
{Options} CONTAINS "Lamination"andCOUNT({Options}); - comment — two slashes to the end of the line.
The full language reference is in the field window itself, below the formula — “Formula language reference”.
If it didn't work
- The result is empty. Most likely the formula contains a field the visitor hasn't filled in yet. Set a “Default value” for such fields.
- The field name in the formula doesn't work. Insert it with the button, not manually: the name must match the field name letter for letter.
- You renamed a field — the formula broke. Fix the formula: it references the name.
Did the article help?
Thank you, we've recorded it.
See also
How to build a formCreate a section with the forms module and click “Add field” — fields are laid out by dragging across columns.What field types are thereAbout thirty types: from a plain string and date to a calculator, dependent lists, and choice buttons.How to set field width and unit of measurement"Width within column" stretches the field, "Unit of measurement" labels it — "pcs", "m²", "rub", or your own option.How to transfer a form to another siteThe "Download form" button saves it as a file, "Upload form" deploys it in another section.
