Documentation, Reference Materials and Tutorials for 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.
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.
- 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.
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.
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.
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.
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).
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.