Formula functions: work out a quote from a form's fields
A formula function turns the numbers a visitor types into a form into a result on the thank-you page: a quote, a deposit, a delivery estimate. You write it as a few lines of arithmetic in the builder's Console. Anticode works it out on its own server in a small calculator language, so there's nothing for you to host and the published page still runs no scripts.
When a formula is enough
Most pricing a small business puts online is arithmetic: a rate per square metre plus a call-out charge, a nightly price times the number of nights, a percentage deposit. None of it needs outside data. Asking an owner to run a server for that is its own barrier, so a site function can be a formula instead of a call to an endpoint. A quote calculator form formula is the typical case. If the answer depends on something outside the form, such as availability in your own calendar, use a site function that calls your endpoint.
Writing the lines
In the Console, open Functions, add a function and choose Calculate from the form. The Lines box takes one result per line, written as Label = formula. A quote for floor sanding might read:
Total = area * 18 + 60 ; currency GBPRush fee = if(rush == 1, 40, 0) ; currency GBP ; hiddenWith rush = total + rush_fee ; currency GBPDeposit = with_rush * 0.25 ; currency GBP
Each line can use the form's fields by name (area, rush) and any earlier line by its label in lower_snake_case (Rush fee becomes rush_fee). After a semicolon come display options: currency with a currency code, percent (so 0.25 shows as 25%), number, a single digit for how many decimals, or hidden for a working step you don't want on the page.
What the language allows
| Kind | Allowed |
|---|---|
| Values | Numbers, form field names, earlier lines, true and false |
| Arithmetic | + - * / % |
| Comparison and logic | < <= > >= == !=, && || !, and a ? b : c |
| Functions | min and max (up to eight values), round (with optional decimals), floor, ceil, abs, clamp(x, low, high), if(test, then, else) |
That's all of it. There are no strings, no property access and no other calls, so a formula has nothing it can reach. Each formula is limited to 300 characters, 120 tokens and 24 levels of nesting, with up to 12 lines per function. Every value has to stay a finite number: dividing by zero is an error rather than infinity. The lines are checked when you save, and a line may only use lines above it, so a mistake shows up in the panel before any visitor meets it.
What the visitor sees
Add a Heading ("Your quote") and a Message that can mention any line or field in braces: "For {area} m², the total is {with_rush}." When the form is sent, the server works out the lines and shows the heading, the message and every line that isn't hidden on the thank-you page, in the site's own design.
Refuse when takes a formula of its own, for example area > 500. If it's true, the form is turned down with your refusal heading and message ("Too large to quote online. Call us for areas over 500 m².") and nothing is stored. Otherwise the submission is saved like any other and reaches your inbox and connectors.
Building the form for it
A quote form usually needs fields the built-in contact form doesn't have, so it's a custom form that posts to /api/fn/<name>. Once the function is saved, the panel shows starting markup with one input for each field the formula uses, set up for decimal entry. Every field the formula reads must arrive as a plain number: digits with an optional decimal point.
- Thousands separators such as
1,200aren't numbers to the formula. Ask for whole figures. - A checkbox sends a word, not a number. For yes-or-no choices use a select whose options have the values 1 and 0, as the rush example expects.
- If a visitor types something that isn't a number, they get a page asking them to check the form, and nothing is stored.
Testing and safety
The Test button runs the formula with sample values and shows what the visitor would see. Because a formula calls nothing outside Anticode, it needs no address, no signing secret, no timeout and no encrypted vault, and it runs in microseconds. It's parsed by Anticode's own small interpreter, never by a general-purpose evaluator, which is why names like constructor are just fields the form doesn't have.
Limits
- No live total. The result appears after the form is sent. The page has no scripts, so nothing updates as the visitor types. If you need a live calculator, an app build of a quote calculator runs in the browser instead.
- Arithmetic only. No lookups in tables, dates, or text handling. For those, call your own endpoint.
- Numbers in, formatted numbers out. Currency formatting follows the code you give, with US-style digit grouping.
- A shared function allowance. Formulas count towards the same per-project limit as endpoint functions: two on Free, twenty on paid plans.
Questions people ask
Do I need to host anything for a formula?
No. The formula is stored with your project and worked out on Anticode's server when the form is sent.
Can the formula use a value from an earlier line?
Yes. Refer to it by its label in lower_snake_case. Only lines above it can be used, which the panel checks when you save.
Can I hide a working step?
Add ; hidden to the line. It's still calculated and can be used by later lines, but it isn't shown on the thank-you page.
What does the visitor see if their input is wrong?
A page asking them to go back and check the form. Nothing is stored, so they can correct it and send again.