Conditional logic
How it works
Each field can have rules that decide when it appears. When a customer changes an answer, SparkLayer checks your conditions and shows or hides fields straight away. You set it all up in the form builder, without code.
A condition has three parts:
| Part | What it is |
|---|---|
| Field | The answer or value you're checking. |
| Condition | How it's compared, such as Equals. |
| Value | What it's compared against: a fixed value, or a reference. |
For example: show State when Country equals "US".
You choose whether the conditions show the field or hide it:
| Action | What it does | Use it for |
|---|---|---|
| Show when | The field only appears when the conditions are met. | Region-specific address fields, optional business details or advanced settings. |
| Hide when | The field disappears when the conditions are met. | Skipping irrelevant questions and shortening long forms. |
Common uses
Use conditional logic to keep forms short and relevant:
| Use | How |
|---|---|
| Region-based forms | Show different fields depending on the country selected. |
| Advanced options | Hide detailed options until a toggle is turned on. |
| Progressive disclosure | Reveal extra questions gradually instead of showing a long form up front. |
| Customer-dependent forms | Show or hide sections based on the logged-in customer's ID, customer group, role or other details. |
Add conditional logic to a field
- In the form builder, select the field (or group) you want to show or hide.
- In Configure field, open the Display logic tab.
- Under Conditional display logic, click Add condition and choose the Field to check. For a field from elsewhere, or for customer or SparkLayer data, use the reference picker.
- Choose a Condition, such as Equals.
- Enter a Value, or click Reference to compare against another answer or data reference.
- To combine several rules with AND or OR, turn on Advanced rules.
Changes save to your draft automatically. To remove all rules from the field, click Clear logic.
To apply the same logic to several fields at once, put them in a Group and add the logic to the group.
Combine conditions
One condition is often enough. For more complex rules, combine conditions with AND or OR, or group them.
| Type | Example |
|---|---|
| Single condition | Show Phone when Contact preference equals "Call". |
| Multiple conditions (AND or OR) | Show Shipping address when Delivery method equals "Ship" AND Country equals "United Kingdom". |
| Condition groups | Show Discount when (Customer type equals "Premium" OR Order total is greater than 1000) AND Promotions enabled is true. |
With condition groups, you can build complex rules without duplicating fields.
Condition types
The conditions you can choose depend on the type of field:
| Type | Examples |
|---|---|
| Equals / not equals | Customer type equals "Trade". |
| Greater than / less than | Order value is greater than 500; quantity is at least 10. |
| Contains | Email contains "@company". |
| Starts with | Phone starts with "+44". |
| Ends with | Email ends with ".edu". |
| Has value | Email is not empty. |
| True / false | Approved is true. |
| Length | Checks on the length of a postcode, reference code or order number. |
What you can reference
Conditions can compare against a value you type, or against other data with data references, such as the logged-in customer's customer group.
What references can point to
- Fields on the same page or earlier pages
- Global (non-repeating) fields
- Fields in the same instance of a repeatable group (inside a repeatable group, logic applies to the current item)
- Fields from other forms
- Data table values
- The logged-in SparkLayer customer, such as their ID, customer group, role and other details
Hidden field behaviour
Hiding a field changes how the form treats it. When a field is hidden:
- It's removed from the form
- Its validation rules no longer apply
- Its Required setting is ignored
- Its value is kept, unless configured otherwise
To clear an answer when the field it depends on changes, use a Clear answer workflow.
Tips
- Keep logic simple. Avoid deeply nested conditions, use clear labels and write down complex rules for your team.
- Use a Group to apply logic once to several fields instead of repeating it.
- Test every condition path, including empty fields, on the Preview tab.
- Don't hide too much at the start, and give context when new fields appear.
- Very complex logic can slow down large forms. If a form grows, split it into pages, simplify nested conditions and reduce dependencies between fields.
Last updated