Form Logic Overview

The four ways to add logic to a survey — validation, skip logic, default values, and calculations — and how question references work

MQUAD surveys support four kinds of form logic. They look similar — all four are small expressions typed into the question properties panel — but each one does a different job:

FeatureWhat it doesDesigner location
ValidationDecides whether an entered answer is acceptableValidation Rules (Advanced section)
Skip LogicDecides whether a question is shownSkip Logic (Advanced section)
Default ValueSupplies an initial answer when the form startsDefault Value (Advanced section)
Auto-Populate / CalculationDerives an answer from other answersCalculated Value or Auto-Populate (Advanced section)

Two of these run once (default values, at form start). Two of them re-run every time a dependency changes (skip logic and calculations). Validation runs every time a value changes.

Tip: Not sure which feature you need? Jump to Choosing the right tool at the end of this page.


Referencing another question

Expressions reference questions by their variable name (the name field), never by their displayed label.

${age}                 — the answer to the question named "age"
${visit_date}          — the answer to the question named "visit_date"

Examples using realistic survey questions:

Question labelVariable nameReference
"What is your date of birth?"dob${dob}
"How old are you?"age${age}
"Are you currently pregnant?"pregnant${pregnant}
"Weight (kg)"weight_kg${weight_kg}
"Select your district"district${district}
"Visit date"visit_date${visit_date}

Correct:

${dob}

Incorrect:

What is your date of birth?

Why the variable name matters

The variable name is the stable identifier used everywhere behind the scenes:

  • Translations — the label changes per language, the variable name does not.
  • Label edits — you can reword a label without breaking any logic.
  • Data exports — exported columns use the variable name.
  • Stable calculations — a calculation keeps working even if someone renames the label.

The variable name must start with a letter or underscore and contain only letters, numbers, and underscores ([a-zA-Z_][a-zA-Z0-9_]*).


Two different reference grammars

MQUAD uses two different reference styles, depending on which feature you are configuring:

FeatureReference styleExample
Validation, Skip Logic, Calculation${question_name}${age} >= 18
Default Value#question_name#country#district

A default value like #country#res_num concatenates the answers of country and res_num. The # grammar is only for default values — you cannot use it in a calculation, and you cannot use ${...} inside a default value.

This is a common source of confusion, so it is called out explicitly in each chapter below.


The current-field value: .

Inside a constraint (validation) expression, the dot . refers to the current question's own value:

. >= 18

means "the answer to this question must be at least 18". The validation builder generates .-based expressions automatically (e.g. . >= 18, string-length(.) >= 3). You can also combine . with other questions:

. >= ${min_age}

"this answer must be at least the value of question min_age".


Choosing the right tool

ScenarioUse
A question must be answeredMark it Required in the question properties
An answer must be within a range, match a pattern, or satisfy a conditionValidation Rules
A question should only appear under certain conditionsSkip Logic
A field should start pre-filled (and stay editable)Default Value
A value should be computed from other answers and update when they changeAuto-Populate (on a normal question)
A read-only computed result should never be editedCalculated Value (type = calculate)

What you'll find in this section

PageCovers
ValidationConstraints, operators, validation messages
Skip LogicRelevance expressions, conditions, nested logic
Default Values#ref syntax, today, now, system variables
Auto-Populate and Calculations${ref} syntax and the full function set
Expression ReferenceEvery operator and every built-in function
Date and Time ReferenceDates, datetimes, plain times, and the frozen rules
Common RecipesCopy-and-adapt examples for real surveys
XLSForm MappingHow these features map to XLSForm columns
Blank and Invalid ValuesWhat happens with null, blank, and bad input
Troubleshooting ExpressionsCommon mistakes and how to fix them

If you are new to survey logic, start with Validation and Skip Logic, then read Common Recipes for real examples.