Forms

Run logic on submit

Forms can do more than save answers. They can run a function, update the page, and change other fields as people type.

Your options

Pick the simplest option that does the job. Built-in actions need no function at all.

On end rule

A function that runs on the server when the form is submitted. Set it in Form settings.

On change rules

Actions that run while someone fills the form, including calling a function or setting a page variable. Set them per field.

Trigger a page event

Runs one of the page's triggers after a successful submission. Set it on the Form element.

Notify admins and Add tags to users

Built-in actions that need no function.

Add an On end rule

1

Build the function

Create and test your function in System Configuration, then Functions. Only active functions can be picked.

2

Open the form

In Forms, then Form Creater, choose Edit on the form.

3

Open the rule

Click Form settings and select On end rule.

4

Pick the function

Choose it under Select Function.

5

Map the values

Under Input targets, choose what each function input receives. Under Output targets, choose which form fields receive each value the function returns.

6

Save

Click Update form.

Changing the function later changes what every submission of this form runs, from the moment you save it.

A current limitation

At the moment, form answers do not reliably reach a function's inputs when it runs as the On end rule. A function that depends on its inputs can fail. The submission itself is still saved.

Until this is fixed, use one of these approaches when your logic needs the answers:

Add an On change rule on the field that calls the function, so it runs with the value as it is entered.

Use On change rules to copy answers into page variables, then choose Trigger a page event after success and let a page trigger call the function with those variables.

Check what ran

Every function run is recorded. Open the function in System Configuration, then Functions, and go to the Runs tab. Runs started by a form are marked Form, with their status, duration and any error.

Test the function on its own in its Test tab before wiring it to a form. It is much easier to fix there.