1. Help
  2. Features
  3. Conditional logic

Conditional Logic

Introduction

Conditional logic is the ability to adapt your form based on user input in real-time. Conditional logic consists of a set of rules, and each rule (or 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.

Here is an example of a support ticket form that shows a different set of fields based on the type of issue selected:

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.

The conditional logic panel can be accessed on the form editor page by clicking on the Conditional logic button in the top right corner.

Conditional logic panel in Formcrafts
Conditional logic panel in Formcrafts

Practical examples

Here are some ways to use conditional logic with forms:

  1. If Enquiry type is Sales, show Company size field.
  2. If Additional person is Yes, show Additional person info step.
  3. If Enquiry type is Refund and Amount is over $100, set value of requires_approval to Yes.
  4. If Are you over 18? is No, disable form and show field Error message.

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.

Conditional logic rule with highlighted a condition

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

If Enquiry type is Refund, show Company size field.

Fields

This is the field that the condition is based on. In the example, the field would be Enquiry 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: Perform an exact match
  2. Is not: Exclude an exact match
  3. Is empty: Check if a field is empty
  4. Is not empty: Check if a field is not empty
  5. Is under: Check if a value is less than
  6. Is over: Check if a value is over
  7. Contains: Check if the field contains a part of another string

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.

Conditional logic rule with a highlighted 'show fields' action

Actions are what happens when the conditions are met. There are several types of actions available, which are discussed in detail below:

  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

Condition groups

You can evaluate your condition as AND or OR.

  • AND: All conditions in the group must be true for the actions to be executed.
  • OR: At least one condition in the group must be true for the actions to be executed.

There are some cases where you might want to use a combination of AND and OR to create complex conditions. Some form builders, like Formcrafts, allow you to nest conditions to create complex logic. We call them condition groups. Each group can choose between AND and OR for its conditions, and the groups as a whole can be AND or OR.

We have a loan application form which contains a hidden field labelled pre-qualified. We use logic to set the value of this field to true if certain conditions are met. The conditions are:

  • Credit score is above 750 OR Income is above 100,000
  • AND Outstanding Debts = None
Highlighted condition groups in a conditional logic step
Conditional groups for advanced scenarios

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.

Conditional logic vs Skip logic

Conditional logic is often confused with skip logic. Skip logic is a simpler form of conditional logic where you skip to a different part of the form based on user input. Skip logic is meant to control the user journey, with respect to the form steps they see.

Skip logic is also sometimes called branch logic. Note that implementations of skip logic differ by provider, and some may offer more features.

Some other differences between conditional logic and skip logic:

  1. Skip logic shows or hides entire form steps, while conditional logic can show or hide individual fields or form steps.
  2. Conditional logic has a wider range of actions, including setting field values and changing field options.
Flow chart showing user journey with skip logic
User journey with skip logic

FAQs

Can conditional logic be used to show custom messages?

Yes, you can use the Rich Text field to add a custom message to your form. You can then use conditional logic to show or hide the Rich Text field based on user input.

Does using conditional logic affect the performance of my form?

Formcrafts' conditional logic is very performant, and has been tested to work with hundreds of condition sets. However, we generally recommend people to stick with less than 50 rules, or 100 rules for complex forms. While it won't affect the performance, managing rules over 100 becomes more difficult.

Can conditional logic be integrated with calculations in form fields?

Absolutely! This can be achieved using hidden fields. Hidden fields can contain math formulas, which are computed in real-time. You can use conditional logic on such hidden fields.

Let's say you want to impose a minimum order value. You have a hidden field which calculates the order total. You can then also have a conditional logic step which disables the form, and shows an error message if this hidden field is less than 100.

Last updated on