# Survey Logic

### Show and Hide Questions

The simplest form of logic is visibility. You can make any question show or hide in real time on the page based on answers to other questions on the same page or previous pages.

To set this up, click the **Edit (Pencil)** icon to the right of a question and configure the **Visibility** settings.

You can also use the **Mandatory** settings to make a question conditionally mandatory, so it is only required if it is shown. For example, make an email address field mandatory only if the respondent has indicated they want to be contacted by email.

<figure><img src="/files/3n7NjhMyls1mZzFELkcU" alt="A screenshot showing how logic and validation being used to show a question only if a condition is met."><figcaption><p>An example of a logic and validation being used to show a question only if a condition is met.</p></figcaption></figure>

***

### Post Logic

Post logic runs after a respondent clicks Next at the end of a page. It can skip pages, jump to a specific page, show a message, or end the survey based on the respondent's answers.

Post logic is useful when you have a group of questions you want to show or skip together based on a previous answer. Rather than setting visibility on each individual question, put them all on a separate page and use post logic to show or skip that page.

<figure><img src="/files/pRteTXxKO4iPnTqve8dL" alt="A screenshot showing post logic being used to determine what action should be taken at the end of a page."><figcaption><p>An example of a post logic being used to determine what action should be taken at the end of a page.</p></figcaption></figure>

Logic conditions are processed from top to bottom. If a condition triggers a page jump or ends the survey, no further conditions on that page will run.

Note that post logic does not process until the respondent clicks Next, so it cannot be used to show or hide questions on the current page in real time. Use visibility settings for that instead.

***

### Pre Logic

Pre logic runs before a page loads. It can be used to skip a page before the respondent even sees it. You can use either post logic or pre logic to achieve similar outcomes, there is no strict rule about which to use. Choose whichever feels most natural for the flow of your survey.

<figure><img src="/files/2qrr5ockoECwxhf0Q0ut" alt="A screenshot showing how pre logic being used determine what action should be taken prior to a page load."><figcaption><p>An example of a pre logic being used determine what action should be taken prior to a page load.</p></figcaption></figure>

***

### Advanced Logic

Logic conditions can be built using answers from anywhere in the survey. If your survey is deployed via a UbiQuity email, you can also use database fields and email interaction data such as whether the contact clicked a link in a previous mailout.

When building conditions, the condition tree gives you access to survey questions, database fields, events, and mailout data all in one place.

<figure><img src="/files/7Ly7PTtGIkY8RBeJTmQ7" alt="A screenshot of the advanced logic conditions that allow you to filter from other modules."><figcaption><p>The advanced logic conditions that allow you to filter from other modules.</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ubiquity.co.nz/documentation/data-capture/surveys/survey-logic.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
