Skip to content

Conditional logic

Steps for

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:

PartWhat it is
FieldThe answer or value you're checking.
ConditionHow it's compared, such as Equals.
ValueWhat 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:

ActionWhat it doesUse it for
Show whenThe field only appears when the conditions are met.Region-specific address fields, optional business details or advanced settings.
Hide whenThe 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:

UseHow
Region-based formsShow different fields depending on the country selected.
Advanced optionsHide detailed options until a toggle is turned on.
Progressive disclosureReveal extra questions gradually instead of showing a long form up front.
Customer-dependent formsShow or hide sections based on the logged-in customer's ID, customer group, role or other details.

Add conditional logic to a field

  1. In the form builder, select the field (or group) you want to show or hide.
  2. In Configure field, open the Display logic tab.
  3. 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.
  4. Choose a Condition, such as Equals.
  5. Enter a Value, or click Reference to compare against another answer or data reference.
  6. 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.

TypeExample
Single conditionShow 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 groupsShow 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:

TypeExamples
Equals / not equalsCustomer type equals "Trade".
Greater than / less thanOrder value is greater than 500; quantity is at least 10.
ContainsEmail contains "@company".
Starts withPhone starts with "+44".
Ends withEmail ends with ".edu".
Has valueEmail is not empty.
True / falseApproved is true.
LengthChecks 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.
Was this page helpful?

Last updated