Click's Form Logic and Conditions utilize expressions. This article will cover the fundamentals of expression syntax so that you can make full use of conditional logic within your Forms and Preference Centers.
About Expressions
An expression is a mathematical formula or logical statement used to specify conditional rules or calculate values. With expressions, you can control the flow of your Form or Preference Center, manage question visibility and read-only state, perform in-form computations, and more. Expressions are evaluated (i.e. calculated to produce a result) in real time while a respondent fills out a Form. This dynamic evaluation ensures that expressions are always up-to-date.
Expressions have a specific syntax that must be followed. While a Form Field's Conditions properties provides a GUI for building expressions, that GUI has certain limitations. So, it is necessary to understand expression syntax if you wish to write your own expressions with maximum flexibility.
Expression Syntax
An expression consists of operands and operators.
Operands are values upon which an operator performs an action. Alongside literals (values like 3, true, or "selected"), expressions can use question values, custom variables, and function results as operands.
Operators are symbols or keywords that define operations performed on operands. Click's Form and Preference Center Designers support comparison, logical, and arithmetic operators.
Expression Operands
Question/Field Values: To use a question/field value in an expression, specify the Question/Field Name property value in curly brackets: {my-field-name}. Upon expression evaluation, the question/field name will be replaced with a real value.
Multiselect and Checkbox fields support advanced syntax for accessing the values of their inner elements. For example, the expression to access the value for the first option in a Checkbox field named "Checkbox1" is: {Checkbox1[0]}.
Custom Variables: Custom variables are user-defined variables used to store dynamically calculated values. Custom variables are created within the Form Designer and Preference Center Designer's page-level Conditions properties section, as described in the "Expressions at Page Level" section below. To use a custom variable in an expression, wrap its name in curly brackets, just like you do with question/field names: {my-custom-variable}.
Function Results: Calculation functions produce results that can be used as operands in expressions. For example, the dateDiff() function computes a difference between two dates, and the function's result can be used in a validation expression to ensure that the difference doesn't exceed a specified limit. All calculation functions are divided into three groups: logical, date, and aggregation functions. A complete list of the available calculation functions is available here.
Expression Operators
Comparison Operators: Comparison operators are used to compare two values (or in case of 'empty' and 'notempty', one value with 'undefined' and 'null') and define whether the comparison is true or false. These operators are essential for managing the Form/Preference Center flow and implementing logic within that flow. A complete list of the available comparison operators is available here.
Logical Operators: Logical operators combine or revert logical conditions to create complex logic for features like visibility, data validation, dynamic read-only state, etc. A complete list of the available logical operators is available here.
Arithmetic Operators: Arithmetic operators perform simple mathematical calculations on numeric values: =, -, *, etc. A full list of available arithmetic operators is available here.
Where To Write Expressions
Click's Form Designer and Preference Center Designer contain Conditions properties at both the page and field levels, as well as a Logic tab (see Form Logic and Preference Center Logic) which provides a consolidated view of the conditional rules created throughout your Form or Preference Center.
Expressions at Page Level
The page-level Conditions properties section contains a section for Custom Variables (used in calculations) and a section for Triggers (actions to be executed when certain conditions are met).
Custom Variables serve as intermediate or auxiliary variables used in form calculations. They take respondent inputs as source values. Each custom variable has a unique name and an expression it is based on.
Click the Add new variable button and you will be presented with a box to configure a variable:
Here you can provide a variable name and an expression defining the variable.
For example, you may have a Single Input Integer Form Field named "Age", and you want to ensure that certain Form Fields are only visible to respondents age 21 or older. In this case, you can name your variable "Age" and provide an {Age} expression to grab the value that has been provided in the Age field:
Triggers are events or conditions that are based on an expression. Once the expression is evaluated to "true", a trigger sets off an action, also written as an expression. Such an action can optionally have a targeted field it affects.
Click the Add new trigger button and you will be presented with a box to configure a trigger:
Click Run Expression to choose the type of trigger that you want to configure. Your options are:
- Complete form: Complete the Form/Preference Center without gathering additional information.
- Set field: Set a field to a specific value.
- Copy field: Set a field to a value copied from another field.
- Skip to field: Skip the user to a specific field.
- Run expression: Run a custom expression.
After selecting your trigger type, you will be presented with boxes to define your expression and select a target field. For this example, we have selected the Set Field trigger type and will be creating a condition to populate this field with "N/A" if the user does not select "Engineer" in the Job Title field:
You can either type your own expression into the expression box, or use the magic wand icon to open an expression builder, which will step you through selecting target fields, variables, and operators for your expression, as shown here:
Clicking Select... allows you to choose a target field or variable for the expression, and clicking Equals will allow you to choose an operator. The available operators are: Empty, Not empty, Equals, Does not equal, Contains, Does not contain, Greater than, Less than, Greater than or equal to, or Less than or equal to.
Upon adding your first condition in this window, an Add Condition button will appear, allowing you to create multi-condition expressions. When you are done adding conditions to your expression, click Apply to accept the changes and close the dialog.
Once you have provided an expression and a target field, you will gain access to a Set posted value button:
Clicking Set Posted value opens a dialog where you can provide the value to be set in the target field when your expression's conditions are met. We have provided "N/A" as the value in this example:
Click Apply to save your provided value and complete your condition.
Expressions at Field Level
The field-level Conditions properties sections provide a graphical user interface for constructing logical expressions - a pop-up dialog with a list of questions and custom variables to select from and available operators.
For example, opening the Conditions properties for a Checkbox Form Field within the Form Designer will present you with a list of suggested Conditions without any expressions:
'
Clicking the Magic Wand icon at the right side of a Condition will open a dialog guiding you through creating an expression for the selected Condition. At first, that dialog box will look like this:
Clicking the "Select" button will open a list of Fields and Variables, if available:
Select the field or variable that you want to base your conditional rule on. Upon selecting a field or variable a corresponding field will appear, along with a new Add Condition button for adding more conditions.
Next, click Equals to select your desired operator: Empty, Not empty, Equals, Does not equal, Contains, Does not contain, Greater than, Less than, Greater than or equal to, or Less than or equal to. Once you have decided on your operator, provide the relevant value in the Field/Variable field.
Use the now-visible Add Condition button to add more and-conditions or or-conditions as needed for your purpose.
When you are done building your rule click Apply to save it. This will populate the corresponding Condition's field with the expression that you built.
For example, here are conditions specifying that a field should become visible only when the user has selected "Engineer" in the Job Title field and 3/01/2025 or earlier in the "Hire Date":
Upon clicking Apply, the corresponding expression is populated in the Make the field visible if condition:
You can erase the condition with the eraser icon, or modify it with the wand icon as needed.
Logic Tab
The Logic tab within the Form Designer and Preference Center Designer provides a consolidated view of all conditional rules existing within the Form/Preference Center, regardless of which area they were created in.
For example, at the end of the "Expressions at Field Level" section of this present article, we showed a Make the field visible if condition configured to only show the "Engineer Feedback" field when the user has selected Job Title = "Engineer" and Hire Date <= 03/01/2025. Even though this was created within the Field-level Conditions properties, it is visible and able to be modified from the Logic tab:
Within the Logic tab, you can click the Add New Rule button to add new rules using a condition-builder very similar to what we already covered in the Conditions properties. For more details about the Logic tabs, see our Form Logic and Preference Center Logic articles.