# Setting-up Conditional Logic on Fields

Sometimes you might have a field in your Form, that you want to show *only* if the user has entered a specific value in another field.

You can achieve this setting by using **conditional logic** on Fields.

## Example

Take a look at the following:

![Example Form](https://1470284034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHN4dErU7ghf8hOdcQpSs%2Fuploads%2Fgit-blob-ff0f3e4d85f600b8efbd4f91cb0246c17b45b311%2FExampleForm.png?alt=media)

In this case, it makes sense to **only** show the email or phone field when the corresponding option is selected in the **How should we contact you?** field.

To enable conditions for the **Email** and **Phone** fields, do the following:

1. Click the `cog` wheel next to the **Email** and **Phone** field. The **Edit question** dialog opens.
2. Select **Enable Conditions** in the **Conditions** section.

   <figure><img src="https://1470284034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHN4dErU7ghf8hOdcQpSs%2Fuploads%2Fgit-blob-c966c9dd1b52caeb611867868706a0c08991cfc1%2FEnableConditions-v9.png?alt=media" alt=""><figcaption></figcaption></figure>
3. Enabling the condition field displays more options:

   <figure><img src="https://1470284034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHN4dErU7ghf8hOdcQpSs%2Fuploads%2Fgit-blob-894fa43a1c5356ac53e6796f867bd46df7be3d57%2Fconditions-v9.png?alt=media" alt=""><figcaption></figcaption></figure>
4. Set the appropriate conditions and click **Submit**.

### Action and Logic Types

There are two **Action Types**:

* Show: the field will be displayed if the rules match
* Hide: the field will be hidden if the rules match

Next up, you'll need to specify the **Logic Type**. This setting is only important if you have multiple rules.

* All: All of the rules must match
* Any: Any of the rules may match

## Adding a new condition

When adding a new condition, you'll need to select the field where you want to evaluate the value and can select an operator.

In this example, we only want to show the **Phone** field if the value of the **How should we contact you** field is `Phone`.

![Setup rule](https://1470284034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHN4dErU7ghf8hOdcQpSs%2Fuploads%2Fgit-blob-894fa43a1c5356ac53e6796f867bd46df7be3d57%2Fconditions-v9.png?alt=media)

Similarly, you can display the **Email** field, if the value of the **How should we contact you** field is `Email`. You can see the conditions added to each field in the Forms designer:

![See conditions in the Forms designer](https://1470284034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHN4dErU7ghf8hOdcQpSs%2Fuploads%2Fgit-blob-2a1c0a8d0d5c1363b9395b7492fcf27cdd7b35f9%2FexampleBackoffice-v9.png?alt=media)

## Result

When both the conditions have been set as shown above, this is how it will look on the frontend:

![Frontend Example](https://1470284034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHN4dErU7ghf8hOdcQpSs%2Fuploads%2Fgit-blob-1d31ab79570a889eb3a46de5857003715ba3699e%2FexampleFrontend-v9.png?alt=media)

In this example, we have only selected **Phone** but it is possible to choose both *Phone*\* and **Email** and display both the fields.

## Conditions for Pages and Fieldsets

As well as showing or hiding a field based on conditions, you can also apply conditions to groups of fields (known as fieldsets) or to pages. The process is the same as described above.

When applying a condition to a page, effectively you are controlling the display of the submit button (for a single-page form) or the next/previous buttons (available on multi-page forms). In this way you can ensure that the entry so far is complete before accepting it or allowing the user to move onto the next page.

## Conditions for Dates

You can apply conditions to dates as well as strings. When you use the date picker field, you can set a condition if a submitted date is greater/less than a specific date.


---

# 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.umbraco.com/umbraco-forms/13.latest/editor/creating-a-form/conditional-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.
