> For the complete documentation index, see [llms.txt](https://docs.rooks.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rooks.ai/build-and-publish-forms/add-conditional-logic.md).

# Add Conditional Logic

Show people only the pages and components that are relevant to their answers or other information available to the form.

Conditional logic helps create a more relevant form experience by controlling which pages and components appear. Conditions can use earlier answers, calculated values, or external variables passed into the form.

In Rooks, conditional logic controls visibility only. It shows or hides the page or component where the condition is applied; it does not jump someone to a particular place in the form.

### Show or hide pages and components

Conditional logic is a visibility mechanism that shows or hides a component or page based on an earlier answer.

The condition is attached to the question or page that should be shown or hidden. The answer controlling that condition ***must come earlier in the form***.

{% hint style="info" icon="square-info" %}
Conditional visibility does not jump someone to a particular page. The person continues through the form in its normal order, while pages and questions whose conditions are not met remain hidden.
{% endhint %}

To add conditional logic, tell the form assistant:

1. Which question or page should be conditional
2. Which earlier question controls it
3. Which answer should cause it to appear

For example:

> Show the insurance provider question only when the person answers Yes to “Do you have health insurance?”

To target a conditional component or page, select it in the **Outline** before describing the condition. The selected element is added to the discussion bar as a reference, so the form assistant knows exactly where to apply the condition. You can also name the page in your request instead of selecting it.

> Show page 2 only when the person answers "yes" to the seeking medical treatment question.

Keep conditions straightforward and based on information that has already been provided, such as a user response, external variable, or calculation based on previous answers. After adding a condition, use **Preview** to test the logic.

### Use calculations in conditional logic

A calculated variable derives a value from answers or other variables in the form. That value can then control whether a downstream question or page is shown.

Describe both the calculation and the visibility rule to the form assistant. For example:

> Add the answers from “Adults attending” and “Children attending.” Show the group-details question when the total is greater than 2.

Rooks creates the calculated variable behind the scenes and updates it when its source answers change. The conditional rule still controls visibility only: it renders or hides the question or page where the rule is applied.

Calculations that depend on unanswered questions cannot produce a result until those answers are available. Test the relevant answer combinations in **Preview** to confirm the intended content appears.

### Use external variables

An external variable receives a value from outside the form without displaying a corresponding question. These values are commonly used for campaign codes, account references, or other information already known before the form opens.

Ask the form assistant to create the variable, specify whether its value is text, a number, or true/false. Explain how it should affect the form, if applicable. For example:

> Create a text external variable named `customerType`. Show the business-details page when `customerType` is `business`.

Pass the value by adding a matching parameter to the form URL:

```
https://forms.example.com/intake?customerType=business
```

Rooks reads the parameter when the form loads and makes its value available to conditional visibility and calculations. If the parameter is missing or its value does not match the expected type, any logic that depends on it may not be satisfied.

{% hint style="warning" icon="square-exclamation" %}
**Keep sensitive information out of URLs**

URL parameters may appear in browser history, analytics, or server logs. Do not use them to pass PHI or other sensitive personal information; use non-sensitive identifiers or reference codes instead.
{% endhint %}
