1. Help
  2. Features
  3. Conditional logic

Conditional Logic

Introduction

The conditional logic panel can be accessed by clicking on the Conditional logic button on the form editor screen.

Conditional logic allows you to adapt your form based on the user input. A conditional logic step has two parts: conditions and actions. Conditions are the rules for user input that you set up, and actions are how your form adapts when the conditions are met.

Conditional logic vs Workflows
Both conditional logic and workflows use conditions. The difference is that Workflows are used to trigger post-submit actions like sending emails or triggering an integration, while conditional logic is used to adapt the form as the user input changes.
Conditional logic panel in Formcrafts
Conditional logic panel in Formcrafts

Practical examples

Here are some ways to use conditional logic with forms:

  1. If Issue type is Refund, show Reason for refund field.
  2. If Additional person is Yes, show Additional person info step.
  3. If Issue type is Refund and Amount is over $100, set value of requires_approval to Yes.

Conditions

This is the first part of a conditional logic step.

Conditions are rules that determine if a particular action should be executed. These rules are being checked in real-time as the user input changes.

Conditions section of conditional logic

Each condition has three segments. Let us look at them in detail, using the first example from the previous section:

If Issue type is Refund, show Reason for refund field.

Fields

This is the field that the condition is based on. In the example, the field would be Issue type.

Operators

This is the operator that is used to compare the field value with the value you specify. In the example, the operator would be is.

The following operators are available:

  1. is
  2. is not
  3. is empty
  4. is not empty
  5. is under
  6. is over
  7. contains

Value

This is the value that the field value is compared with. In the example, the value would be the string Refund.

The value can also be dynamic. You can use @ to reference other field values in the form.

For example, if you want to disable the form if the value of Email does not match the value of Confirm Email, you would use the following condition:

If Email is not Confirm email then disable form.

Actions

This is the second part of a conditional logic step.

Actions section of conditional logic

Actions are what happens when the conditions are met. There are several types of actions available:

  1. Show fields
  2. Show steps
  3. Set value
  4. Set options
  5. Disable form

Show fields

Here is a key thing to remember when working with Show fields: By default all fields are visible. However, if certain fields are made visible using conditional logic those fields will be hidden on form load. They are only made visible when those conditions are met.

Examples:

  1. If Service Rating is less than 3 stars, show fields What went wrong and Suggestions for Improvement.
  2. If Attendee Type is Student, show the field University Name
  3. If Attendee Type is Professional, show fields Company Name and Job Title.

Show steps

The same applies to Show steps: By default all form steps are visible. However, if certain steps are made visible using conditional logic those steps will be hidden on form load. They are only made visible when those conditions are met.

  1. If Do you have previous work experience? is Yes, show step Work Experience Details.
  2. If Type of loan is Mortgage, show step Property Information.
  3. If Type of loan is Personal loan, show step Financial Information.

Set value

This action allows you to set the value of a hidden field.

Example:

  1. If Overall experience is Dissatisfied and Service quality is Poor, set value of hidden field follow_up to Yes.
  2. If Total order amount is over 500 and Have you ordered from us before? is No, set value of hidden field discount_percent to 15.

Set options

This action allows you to change the available options for a dropdown or checkbox field.

Example:

  1. If Program type is Graduate, set options of Department to Agriculture, Resources, and Computer Science.
  2. If Program type is Undergraduate, set options of Department to Math, and Computer Science.

Disable form

This action allows you to disable the form.

Example:

  1. If Event date is less than 0 then disable form.
  2. If Are you over 18? is No then disable form and show field Error message.

Note: Event date being less than 0 means that the event date is in the past. See more below.

Notes

Working with dates

You have to enter a date in the format YYYY-MM-DD when working with dates. Example:

If Date is under 2024-01-01 then disable form.

However, you can also use dates relative to today. Today is represented by 0. Seven days from today is represented by 7. Five days before today is represented by -5. Example:

If Date is under -5 then disable form.

This would disable the form if the date is 5 or more days before today.

Tabular field

Tabular fields cannot be used in conditions.

Condition groups

Conditions can be chained together using AND and OR operators. This allows you to create complex conditions, like our last example:

If Issue type is Refund AND Amount is over $100, set value of requires_approval to Yes.

Condition groups take this one step further.

We want to extend our example so that requires_approval is set to Yes if Issue type is Exchange (regardless of the amount), while also keeping the existing condition.

We can use use a condition group to achieve this:

Using conditional logic groups in Formcrafts
Using conditional logic groups in Formcrafts

Conditional logic vs Skip logic

Skip logic (not supported by Formcrafts) is similar to conditional logic. Skip logic allows you to create different routes or form journeys. It can be simpler to setup but is limiting in its capabilities. Conditional logic is more powerful and flexible.