Anticode

Anticode site functions: run your own logic when a form is sent

Anticode site functions run on the server when a visitor sends a form, and show the result on the thank-you page. A function is either a small formula, such as a quote calculator, or a signed call to your own HTTPS endpoint. Anticode never runs your code itself; the page still runs no scripts.

Updated · By the Anticode team

Two kinds of function

Formula
Arithmetic over the form’s fields, such as rooms * 45 + (deep_clean ? 30 : 0), worked out on the server by Anticode’s own small parser, never by eval. It works on numbers only: no text, postcodes, dates or lookups. It can refuse the form with its own message, and a refused form isn’t saved.
Webhook
Anticode sends the form to your HTTPS endpoint, signed with an HMAC in the anticode-signature header, and shows the heading and message your endpoint returns. Your server can do anything it does already.

What a formula can use

  • Numbers, form field names and the names of earlier lines (a formula can have up to 12 lines).
  • The operators + - * / %, comparisons, && || !, and a ? b : c.
  • The functions min, max, round, floor, ceil, abs, clamp and if.
  • No strings or property access, so there is nothing outside the form to reach.
  • Up to 300 characters, 120 tokens and 24 levels of nesting per expression. Every value must stay a finite number: dividing by zero is an error, and a field that isn’t a number makes the form ask the visitor to check it.

Add a function step by step

  1. Open the project’s console and choose Functions.
  2. Create a function, give it a name, and choose formula or webhook.
  3. Write the formula, or paste your endpoint’s https address and keep the signing secret it shows.
  4. Set the thank-you heading and message; values the function computes can be filled in.
  5. Attach it to a custom form (which posts to /api/fn/<name> with up to 30 plain-text fields) or to the built-in booking, contact or newsletter form.
  6. Send a test form and check the thank-you page.

On built-in forms

On a booking, the slot check runs first, then the function, which can refuse the booking with its own message or add one to the thank-you page. The same applies to built-in forms inside app builds; whether the app shows the function’s message depends on the app, so test it.

Verify the signature

Your endpoint should recompute the HMAC of the request body with the secret and compare it with anticode-signature before trusting the request. A request without a valid signature didn’t come from Anticode.

Limits

  • Nothing is calculated live as the visitor types, because published pages run no scripts; the result appears after sending.
  • The heading and message are fixed text with values filled in.
  • Custom forms live on design-engine pages; apps can’t use them.
  • Submissions from custom forms are stored like any other (as fn:<name>) and sent to your connectors; email lists still take newsletter sign-ups only.

Example: a cleaning quote

A custom form asks for the number of rooms and whether the visitor wants a deep clean. The formula rooms * 45 + (deep_clean ? 30 : 0) works out a total; a second line refuses more than 12 rooms with a message asking the visitor to call. The thank-you heading reads “Your estimate” and the message “About {total} for {rooms} rooms. We’ll confirm by email.” Nothing runs on the page: the visitor sends the form and sees the result.

Questions people ask

Can a formula use a postcode or a date?

No. Formulas work on numbers only; use a webhook function for anything else.

Does Anticode run my code?

No. A webhook function calls your endpoint; Anticode only runs formulas, which are arithmetic.

Is a refused form saved?

No. A form a formula refuses isn’t stored.

Can I call an outside API from a formula?

No. Formulas only do arithmetic; a webhook function can call anything from your own server.

How fast is a webhook function?

It runs while the visitor waits for the thank-you page, so keep your endpoint quick.

Can a function send an email?

A webhook function can do anything your server does, including sending email.