Let’s get started by creating the form with the WordPress Form Maker. From the submenu of the plugin go to the
> Forms page,
> choose an already-created form or create a new one by following the steps in this guide.
Note: Make sure to add all necessary fields to your form.
> Navigate to “Form options” of your form,
> Click on the “Conditional fields” tab.
Press ”Add Condition” button to configure the first condition of your form. The options to configure the conditional logic will appear.
Let’s go through all of them one by one:
1. Set the action of the condition to: Show or Hide,
2. Choose the field to which that action will refer to,
Note: If you have address fields, by choosing "Address" from the name dropdown menu, you will choose the entire address instead of choosing address line 1, address line 2, so on so forth.
3. Choose in which case the condition should occur: if all or if any of the selections match.
Click the little Plus (+) icon to add the statement of your form condition.
- Select the field that you would like this logic to depend on.
- Select which logical comparison you would like to check:
- is,
- is not,
- like,
- not like,
- empty,
- not empty.
3. Select or fill in the value that the field should contain for the assigned condition to apply.
Now let’s consider two examples of conditional logic:
- Simple Conditional Logic;
- Complex Conditional Logic (applying conditional logic to a field with its own conditional logic).
Simple Conditional Logic
Let’s consider the case when you are asking the user to choose the means of communication after they contact your team.
The condition you configure needs to have the following logic:
The user will see the field asking for his or her email/phone number only if he or she chooses email/phone as a preferred method of communication.
Go ahead and set up the first condition for emails:
[Show] [Email field] if [all] of the following match:
[Means of communication] is [Email]
and then add the second condition to show the phone field:
[Show] [Phone field] if [all] of the following match:
[“Means of communication”] is [Phone]
Complex Conditional Logic
For instance, you want to show the field “Means of communication” (with its own conditional logic that we have created in the section “Simple Conditional Logic”) if the age of the user is 25 and he/she lives in Tokyo. Let’s also assign the form to show the reason for rejection in case the conditions are not fulfilled.
The conditions you configure need to have the following logic.
Condition 1: (the user lives in Tokyo and is 25 years old)
[Show] [“Means of communication” ] if [all] of the following match:
[Age] is [25]
[City] is [Tokyo]
Condition 2: (If the above statement is true, hide the Reason)
[Hide] [Reason] if [all] of the following match:
[Age] is [25]
[City] is [Tokyo]
Condition 3: (If the user lives in Tokyo and is 25 years old, we need to receive contact info)
[Show] [Email field] if [all] of the following match:
[Means of communication] is [Email]
and add the second condition to show the phone field:
[Show] [Phone field] if [all] of the following match:
[Means of communication] is [Phone]
Congrats! We have just created a form with complex conditional logic.