Toggle menu

Form Functions, Handlers and Signatures

Execution Order

The forms designer lets you add JavaScript to your form that is executed at particular points in a form's lifecycle. The The Form Lifecycle: Control and Action Processing describes how forms are rendered and their actions processed, and The Form Helper Library has more information about writing functions.

This table describes each function/handler. They are executed in order, with those at the top of the table first.

Function/HandlerExecutedDescription
Form Server-side Initialisation HandlerServer-sideThe server-side initialisation handler found in the Form Settings menu. This is the first function to be executed before the page is rendered. It will be executed on every page. As this handler needs to take into account all pages, the Page Handler is often easier to use
Page Server-side Initialisation HandlerServer-sideThe server-side initialisation handler found in each page's settings. This function is executed after the form-level handler but before field default functions
Default FunctionsServer-sideAlmost every field can have a default function. This property lets you enter a script that will be executed server-side as the field is generated.

It is mostly used to set the value of the field. That could be by calling another service (an end point for example) or by calculating the value based on what's been entered in previous pages of the form
Form Client-side Initialisation HandlerBrowser-sideThe form client-side initialisation handler.

Allows you to enter script that is executed browser-side on every page once the page has been rendered. As this field needs to take into account all pages, the Page Handler is often easier to use
Page Initialisation Client-side HandlerBrowser-sideThe page initialisation handler.

Allows you to enter script that is executed browser-side once the page has been rendered. It is useful for showing and hiding multiple fields on a page
Validation FunctionBrowser-side repeated Server-sideAlmost every input field has a validation function. This property lets you enter a script that will calculate whether the value of the field is valid or not.

Validation is performed browser-side as field values are updated, and repeated server-side between pages and when the form is submitted (in which case a failure will reload the page and display the error).

Returning true for valid, false for invalid will display the fields default error message. Return a map in the following format to catch the errorType in a field's error message function:

{
    isValid: false,
    errorType: 'CUSTOM_ERROR'
}
HandlersBrowser-sideField handlers are executed browser-side on page load and are also triggered whenever the value of the field changes. Whether the value of a field is valid or not is passed to the handler function as a parameter.

The scripts you enter here will power much of the dynamic behaviour of your form. Handlers can be used to show and hide fields, update field values, disable fields, change the options available in drop-downs, to name just a few

Handlers have built in protection against circular events to prevent one field updating another, which then attempts to update the original field again

As each page of your form is requested, loaded, interacted with and submitted, the following cycle takes place.

The cycle starts at the top, with a browser making a request to your site for a form. The form is then rendered in the first blue block, and appears to the user at the beginning of the first green block.

 

Form Page Lifecycle
 

Last modified on 25 March 2024

Share this page

Facebook icon Twitter icon email icon

Print

print icon