Toggle menu

Form Variable

This field creates a form variable. The name of the variable will be the name of the field unless the Variable Name property is set, in which case the name of this property will be used.

The initial value of the variable can be specified in the Value property or returned by the Default Function. If the Default Function is used, the current value of the variable, if it exists, will be supplied as the currentValue parameter to the the function.

The Scope property defines where the variable can be accessed.

The Form Variables knowledge base article has more information and several examples of form variables being used.

Properties

LabelDescriptionType Name
Variable NameThis is the case-sensitive name of the variable. If no name is specified the field name will be usedVARNAME
ValueA default value for the field, assigned when the page is loaded. The value will always be stored and returned as a string, so 123 becomes "123".

A default value is always overridden by a value generated by the default function (which also correctly preserves the type)
VALUE
ScopeThe scope defines where the variable can be accessed.

Various combinations of Browser and/or Server side access are available.

Server only
This is the default. 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 & Browser
The variable will be available in any function executed on the server on any page of the form after the appearance of this field. Any changes made to its value in this function will be saved. It will also be available to any function executed on the browser. Any changes made to the variable by function executed on the browser will only be visible to the current page on the browser. No variable changes are submitted back to the server.

Server & Browser with updates from Browser
The variable will be available in any function executed on the server on any page of the form after the appearance of this field. Any changes made to its value in this function will be saved. It will also be available to any function executed on the browser. Any changes made to the variable by function executed on the browser will be visible to the current page on the browser and passed back to the server when the page data is successfully stored.

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 function on the current page executed on the browser. It is not available to any server function and any changes made on the browser will not be submitted back to the server.
SCOPE
Default FunctionA JavaScript function that can be used to generate the default field value. This function is executed server-side when the field HTML is generated and overrides any fixed value entered above. For example:

function (helper, defaultValue, currentValue) {
    var theValue;
    // Code to initialise the value
    // theValue = ...
    return theValue;
}
DEFFUNC
HandlersA JavaScript function that is executed client-side whenever the page loads, or the field value changes. This function is useful for executing some JavaScript whenever the helper variable's value is updated by a call to helper.setVariable(). It has the following format:

function (helper, fieldName, value, valid, eventName) {
    if (eventName == 'CHANGE' && valid) {
        ...
    }
}

Where fieldName = the name of the field that changed
value = the new value of the field
valid = whether the field validated successfully
eventName = the name of the event triggering. Always 'CHANGE'

This function is never called on the server.
HANDLERS
DocumentationAdd documentation to your field to help explain any complex functionality to future users. You might include information on what the field does and how it relates to other fields on the form. Notes added here are only ever visible in the Forms Designer, they can be searched for, viewed and downloaded from the action panel. See Common Field Properties for an exampleDOCUMENTATION
Last modified on May 09, 2023

Share this page

Facebook icon Twitter icon email icon

Print

print icon