WPForms Documentation

Documentation, Reference Materials and Tutorials for WPForms

How to Use Conditional Logic with WPForms

Would you like change how your form behaves based on what the user selects or enters into a field? Conditional logic allows you to change what the user sees in your forms, or even what notification email gets sent out.

In this tutorial, we’ll introduce you to conditional logic in WPForms.

If this is your first time creating a form with WPForms, then be sure to first take a look at this article on creating your first form with WPForms.

Basic Conditional Logic

For this example, we’ll make a single field appear when the user selects a specific option from a dropdown field.

1. Let’s get started by opening the form builder. From there, click on the form field that you want to show or hide. This will open its Field Options panel.

2. If you scroll down on the Field Options panel, you should see a Conditionals section. Go ahead and click this to expand it, then check the box labeled Enable Conditional Logic.

Enable conditional logic for a field

3. Now that conditional logic has been enabled, you should see a few dropdown options. The criteria available for selection depends on the fields you already have in your form.

Here are the questions you’ll need to consider when filling in these dropdowns:

  • Show/Hide: Would you like this logic to cause the field to be shown or hidden when conditions are met?
  • Select Field: Which field would you like this logic to depend on?
  • Comparison: What comparison would you like to use on this field? Options include: is, is not, empty, not empty, contains, does not contain, starts with, and ends with.
  • Conditional logic options

  • Select Choice: What value would you like the field to contain in order for this condition to apply? This field will deactivate if you select empty or not empty from the comparison dropdown.

Go ahead and fill out each of these dropdowns. For our example, we’ll apply conditional logic to our ‘Other Business Type’ field. Here, we’ll set the logic to Show this field if the Business Type dropdown is set to Other.


Complex Conditional Logic

You may find that a single set of conditional logic isn’t complex enough for some situations. It’s possible to add as many conditions as you like.

When adding multiple conditions, be careful that they don’t conflict with one another. It’s always a good idea to test our your form (either in the form preview or on a private page) before putting it on a live page or post.

In our example form, let’s add a checkbox field that will only display if the user selects either Farming or Ranching from our Business Type dropdown.

1. First we’ll add a Checkboxes field and customize the text content.

Add a checkbox to use for conditional logic

2. Next, we’ll repeat the process from above to enable conditional logic and add our first condition. For this example, we’ll start by showing this field if Business Type is Farming.

Start with simple conditional logic

3. Now that we have the first condition set, we have to decide whether to use AND or OR conditional logic for the second condition. If we wanted to require the user to select both Farming AND Ranching, we would need to select the grey AND button. This would work well if we were using checkboxes, so it would be possible for the user to select both of these options at the same time. It would also mean this field would only display if both Farming and Ranching were selected.

However, it’s not possible to use AND logic on two options in the same dropdown field as the user can only select one option at a time.

For our example, we want the field to display if the user selects Farming OR Ranching, so we’ll click the Add new group button to add OR logic.

Click the Add new group button

When you click this button, you’ll notice an ‘or’ is shown below the existing logic, before the new condition. This means that our field will display even if only one of these conditions is met (if the first OR second condition is met).

Add more complex conditional logic

For more details on both AND and OR conditional logic, be sure to check out our video and tutorial.

That’s it! We hope this article helped you learn how to use conditional logic with WPForms.

Want to see more examples of how to use conditional logic in your forms? Check out our tutorials on how to let users select a payment method and how to send different notification emails based on user selections.