Toggle menu

Form Variables

Form variables store values used by your forms. They can be generated server-side as form pages load, and be created and updated as users fill out form fields.

They are similar in concept to a global JavaScript variable, encapsulated within the helper library of a single form. If multiple forms are rendered on the same page they have independent variables which may have the same name.

Form Variable Scope

Form variables are stored with a scope. The scope defines where a variable is available, whether or not it can be updated, and whether changes are saved with the form submission. This means you can create a form variable and reuse its value on any page of your form, have a server-side variable just on the current page, create variables that can be accessed server-side and browser side, and create variables whose values can be persisted and updated.

Once set, the scope of a variable cannot be changed. The five scopes are:

Server Only

The variable will be available to any functions executed server-side on any page of the form. Any changes made to its value in subsequent server-side functions will be saved.

The variable value is stored in the iCM database and will not appear browser-side, so it can be used to store more sensitive information if required. The value of the variable can be retrieved in the default functions of other fields.

Server Only Not Saved

The variable will only be available to other default functions executed when building the current page.

Browser Only

The variable will be available to any browser-side functions on the current page. It is not available to any server-side functions and any changes made browser-side will not be submitted back to the server.

Server & Browser

The variable will be available to any functions executed server-side on any page of the form. Any changes made to its value in subsequent server-side functions will be saved.

It will also be available to any functions executed browser-side. Any changes made to the variable by browser-side functions will only be visible to the current page of the form. No changes made browser-side are submitted back to the server.

Server & Browser with Updates from Browser

The variable will be available to any functions executed server-side on any page of the form. Any changes made to its value in subsequent server-side functions will be saved.

It will also be available to any function executed browser-side. Any changes made to the variable by browser-side functions will be visible to the current page of the form and passed back to the server when the page data is successfully stored, making those changes available to subsequent pages.

Creating Form Variables

When working browser-side you can only create non-persistent, browser-side variables. If you want your variable to be available server-side, available on the server and browser, or to be updated by actions on the browser and sent back to the server, it must first be created server-side.

Form Variable Field

Form variables can be created using the Form Variable field type. This field lets you set the variable name, its default (static) value, dynamically generate a default value using a default function, and pick the variable's scope.

Helper Functions

Two functions let you create form variables. .createPersistentVariable defaults to creating server-side, server only variables. .setVariable defaults to non-persistent browser only variables.

Last modified on July 12, 2022

Share this page

Facebook icon Twitter icon email icon

Print

print icon