Using conditional logic in WordPress allows users to create dynamic form fields that collect only the most relevant information when needed.
If you want to provide your users with all the necessary fields but don’t want to clutter your form fields, then a conditional field is the best option for you.
Conditional logic allows your WordPress forms to change or show additional fields based on the user’s selections, show custom text fields, and many more.
How To Enable Conditional Fields
You can use conditional logic to most of your forms field depending on the information you need from users.
Let’s take for example this simple Registration Form.
You want your users to also add their phone numbers instead of just their names and email addresses.
- To enable conditional fields on your WordPress site go to your Dashboard, navigate to Users > Custom Fields > Customize fields.
- You can either edit existing fields or add new custom fields.
- You need to have separate fields for your existing field and your conditional fields. Your conditional field is the one that will appear if the conditions are met on your existing field.
- In this example, we will use the ‘Add Phone Number’ field as the existing field, and the ‘Phone Conditional Logic’ field as the conditional field.
- To enable the conditional logic choose your desired conditional field and then click ‘Edit field’.
- Select ‘Conditional Logic’ then turn on the ‘Enable conditional logic’. Select what conditions you want to meet for your conditional field to appear or function.
- In this example, you want the ‘Phone Number’ (conditional) field to appear if the ‘Add Phone Number’ (existing single checkbox) field has value. Then click ‘Save Changes’.
- After you enable the conditional field, the next step is to add both the existing field and the conditional field to your registration form.
- To do that go to your Dashboard, navigate to Users > Registration Forms > Customize Form.
- On your Registration Form field, drag and drop both the ‘Existing Field’ and the ‘Conditional Field’ from the list of the Available Fields to your Form Fields.
- Your changes will be automatically saved and your conditional field is now ready.
Testing the Conditional Logic
To test your conditional logic field log out of your account, open your website, and go to your Registration form. The Existing field should appear, which is the ‘Add Phone Number’ field in our example.
You will notice that the conditional field, which is the ‘Phone Number’ does not appear on the Registration form because the condition is still not met.
To meet the conditions you set, select the ‘Add Phone Number’ checkbox and the conditional field will appear below the existing field.