How Conditional Logic Works
Conditional logic in Formbricks uses a conditions-and-actions pattern:- Conditions: Define rules based on element responses, variables, or hidden fields
- Actions: Specify what happens when conditions are met (e.g., jump to a specific block or ending)
Setting Up Conditional Logic
Add Logic to a Block
Click on any question block, then look for the “Conditional Logic” section with the split icon.
Create Logic Rules
Click “Add Logic” to create your first conditional rule. Each rule consists of:
- Conditions: One or more criteria that must be met
- Actions: What happens when the conditions are satisfied
Logic Structure
Conditional logic is defined in thelogic array on each survey block:
Condition Types
Left Operand can reference:element- A question/element responsevariable- A survey variablehiddenField- A hidden field value
- Equality:
equals,doesNotEqual - String matching:
contains,startsWith,endsWith - Comparison:
isGreaterThan,isLessThan - State checks:
isSubmitted,isSkipped,isEmpty,isNotEmpty - Array operations:
equalsOneOf,includesAllOf,includesOneOf
packages/types/surveys/logic.ts:8.
Configuration Examples
Example 1: Simple Skip Logic
Show different questions based on a Yes/No answer:Example 2: Multiple Conditions with OR Logic
Jump to a specific block if user selects any of multiple options:Example 3: Nested Condition Groups
Complex logic with nested AND/OR conditions:Example 4: Using Hidden Fields in Logic
Branch based on hidden field values:Practical Use Cases
Customer Satisfaction Survey
- If rating ≤ 3, ask about specific pain points
- If rating ≥ 4, ask about favorite features
- If rating = 5, request a testimonial or review
Product Qualification
- Skip technical questions for non-technical users
- Show pricing questions only to decision-makers
- Display different feature sets based on user role
Multi-Path Onboarding
- Different flows for individual vs. business users
- Customize questions based on company size
- Skip irrelevant sections based on use case
Feedback Collection
- Show bug report form if user experienced issues
- Request feature suggestions from power users
- Collect different data from new vs. returning users
Best Practices
- Test All Paths: Use survey preview to test every possible logic branch
- Use Descriptive Names: Label blocks clearly so logic rules are easy to understand
- Document Complex Logic: Keep notes on complex branching patterns
- Consider Fallbacks: Always define what happens when no conditions match
- Limit Nesting Depth: Deep nesting can make logic hard to maintain
Implementation Reference
The conditional logic implementation can be found in:- Type definitions:
packages/types/surveys/logic.ts - UI component:
apps/web/modules/survey/editor/components/conditional-logic.tsx:42 - Logic editor:
apps/web/modules/survey/editor/components/logic-editor
Related Features
- Hidden Fields - Pass data for use in conditional logic
- Multi-Language - Combine with i18n for localized branching
- Webhooks - Trigger different webhooks based on survey paths