How to Use Conditional Logic in Forms

Basics

Conditional Logic allows you to take actions based on a user's interaction with the form. Some examples:

  1. Send an admin email to sales@example.com if user checks 'Sales' in the Department field
  2. Show a text field if the user checks Yes in the More info field
  3. Hide submit button if the user selects No in the Accept Terms field
  4. Trigger MailChimp integration if the user chooses Yes to the Subscribe checkbox field
  5. Redirect to http://example.com/next if the user selects Yes to Give Me Next Steps field

Where is It?

To access the conditional logic panel click on the Logic icon on the top-left corner, on the form edit page.

conditional-logic-form

A logic step has two parts:

  1. Conditions: This is a user input.
    field32 is Yes
  2. Actions: What happens when the above is true?
    redirect to http://example.com/

Conditions:

A condition is something that depends on user input or selection. Conditions can use one of the following comparison types:

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

Actions:

There are 6 possible actions:

  1. show fields
    You can show certain fields based on user input. Example:
    Condition: Issue Type is Refund
    Action: show fields Order ID, Comments
  2. send emails to
    You can send email notifications to certain addresses. Example:
    Condition: Issue Type is Sales Enquiry
    Action: send emails to sales@example.com
  3. redirect to
    Redirect the responder on form submit. Example:
    Condition: Your Comments contains Confused
    Action: redirect to example.com/help/faq
  4. set value
    You can set the value of a field if certain conditions are met. This is a powerful tool when used alongside math formulas.
  5. trigger addon
    FormCrafts has dozens of third-party addons. By default all enabled addons are triggered when you submit the form. Using this logic you can choose to trigger an addon only when certain conditions are met. Example:
    Condition: Newsletter is "Yes, please do"
    Action: trigger addon MailChimp

Some Examples

#1: Show & Hide Fields

We are creating a support ticket form and we ask the user for the nature of their issue. Based on their selection we will show links to some online resources. If they are not satisfied, we will allow them to submit a complaint.

We begin by adding a checkbox field labelled Issue Type and some possible options. Next we add text fields, one for each issue type containing links to resources. We add another checkbox field with one option, no==This does not resolve my issue and then a comment field and submit button.

We will configure logic steps as such:

Conditional logic to show / hide fields

The first three logic steps show text fields containing links based on user's Issue type selection. They also show the This is not helpful field. The last logic step shows the Describe the Issue field and the Submit button if the user checks the This is not helpful checkbox (whose value is no) or they select the Issue Type as Other.

#2: Send Email to / Redirect

Our organizations has different departments, but we want to use a common form to get user response. We can use conditional logic to route the responses to the appropriate department, and then also redirect the user to a URL for further information.

We add a checkbox field to our form labelled Department with some options.

Next we configure our logic steps as such:

#3: Set Value

We are creating a quiz form. Once we have added all the question fields, we add two Hidden Fields to our form (Add Field → Other → Hidden), labelled Score and Message. We edit the Score field and under value we use math formula to sum the question fields. This hidden field will contain the user's quiz score. We leave the message field empty, but note the field ID, field19

Now we use conditional logic to show the user a message based on their score. If their score is less than 3, the message is, Next Time, and so on ...

The set value action uses this format

fieldID: field value

So in our case:

field19: Next Time

We have the message stored in a hidden field. Now we will show this message when the user sees the success text on completing the form. Go to Settings → General → Form Success Text and edit the text to include the Score and Message.

Special Cases

Datepicker Field

While using logic the value of a datepicker field is the difference of the selected data and today. If today is 1-Jan-2020, and the user selections 14-Jan-2020 in the datepicker field, the value used for logic is 14.

Fileupload Field

With a fileupload field the value is the number of files uploaded so far.

Tabular Field, and Matrix Field

These fields are a composite of smaller fields, and cannot be used with conditional logic.