Blog

How to Add Conditions to Fields in WordPress Form

Why Add Conditions to Fields in WordPress Form?

Conditions are implemented to display questions based on previous answers in a form. Adding conditions to fields in WordPress form display a field based on the value selection of another field. These are rules applied to questions or field items determining when those field items will be shown.

For instance, the user gives a poor rating for the first question. In that case, he has to answer a follow-up question stating the reason for discontent. Adding a condition to the second question makes it appear only if the user rates you within a selected range.

Let us discuss an example where a user, only if he/she is Canadian is asked for the driver’s license number.

Navigating to Fields Manager to Add Conditions

From your RegistrationMagic dashboard, go to the fields section of any form.

Add a “Drop Down” field from the “Add Field” option. Label the field stating “Are you from Canada?”. Next, add the number of options you want to your dropdown list. In this case, we add two values “Yes” and “No” separated by a comma.

To know how to add a field to a form, check our our field addition guide.

Save the field settings and go back.

Now add a “Text” field in a similar fashion. Also, assign its label as “Driver License Number”. Click save and return to the “Fields Manager” page.

When back on the “Fields Manager” page, click the “Conditions” icon for our new text field.

Clicking on the icon will open the “Conditions” configuration popup. From this popup, select the “Action” as “Show Field” and in the “Conditions” section select the field “Are you from Canada?” in the first drop-down. Navigate to the drop-down adjacent to it and select “Equals”. There is a field placed next to the drop-down which will accept the value for the condition to trigger. Fill it with the text “Yes”.

Next, save the condition settings by clicking the “Save” button in the popup.

View From the User End

Now let’s open the form on the frontend and view our condition changes for the field in action. As soon as the forms loads, you can see that the “Driver License Number” field isn’t visible.

Now, we’ll select the option “Yes” for the “Are you from Canada?” field and see what that does.

The “Driver License Number” field is now visible. So our condition settings are working flawlessly.

Multiple Conditions on Single Field

It is possible to have more than one fields affect the visibility behavior of a field. Let’s say we had another field in our form that asked for the user’s age. Now we want to show the “Driver License Field” if “Are you from Canada?” is “Yes” and age is 18 or more than it.

Open the “Conditions” settings popup once again for the “Driver License Number” field. Here, you can see there a “+” icon at the bottom of the existing condition.

Click on this “+” icon and a new field condition will be added to the list. And also a new option will appear on the top of the list asking you whether you want the conditions to work with the “AND” logic or the “OR” logic.

Now, on the frontend, the “Driver License Number” field will only be visible when both the defined conditions are true.

This concludes our tutorial of adding conditions to fields in WordPress form.

Subscribe
Notify of
guest

13 Comments
Inline Feedbacks
View all comments
saurabh.arvind@gmail.com
saurabh.arvind@gmail.com
1 year ago

Is it possible to Show a Text/ Hyperlink based on the selected option of a a Radiobutton

RegistrationMagic
Admin
RegistrationMagic
1 year ago

Hi Saurabh,

You can add links within your forms using the “Link” display field. However, it does not support conditions based on another field’s value. We have noted your requirement though and will plan on adding this to our plugin in a future update.

Francesco
Francesco
3 years ago

Hello,

is it possible to redirect the user after submission to different pages and/or perform different actions with the plugin depending on the users’ field selection?
I mean is the conditional logic limited to the display in the frontend or can I change also the behaviour? I was not able to find any documentation related to my question.

Thanks in advance

RegistrationMagic
Admin
RegistrationMagic
2 years ago
Reply to  Francesco

Hi Francesco,

Post-submission redirection is not based on value selection for a field. Having said that, you may utilize multiple forms to achieve your objective.

Jean
Jean
5 years ago

Hi, how to put message in multiple page if condition is not ok ?

For example :

Have you more 18 years ?

Yes ——> next page of multiple page Form
No ——> Sorry you not the minimum âge to continue

???

RegistrationMagic
RegistrationMagic
5 years ago
Reply to  Jean

You Need to add Birth Date field on the form and then check- ‘Required field’. Scroll down and click- ‘Advanced settings’. Range- Limit range of birth date and here you can set maximum date as well as the minimum date. Add to form when done.

Steve
Steve
5 years ago

Are there any themes/plugins that conditions do not work with? I’ve followed the directions here in the samples and the conditional fields always show up on the form. I’m using the Avada theme, and I just cannot seem to make this work.

RegistrationMagic
RegistrationMagic
5 years ago
Reply to  Steve

The conditional field works fine with any themes. It seems to be a conflict issue with some plugins installed at your end. Kindly deactivate other plugins except RegistrationMagic and confirm whether the issue still persists.

Aaron
Aaron
6 years ago

Can you not have a sign in and register button on the same page depending on whether or not someone has registered?

RegistrationMagic
RegistrationMagic
6 years ago
Reply to  Aaron

We can display sign-in and register button on the same page, but buttons’ visibility will be independent of the condition whether user accessing the page is registered or not.

David Henley
David Henley
6 years ago

How do you add a condition to a file upload field? We have membership levels, some of which offer logo representation on event collateral. We don’t want to display this field if the membership level they select does not offer that benefit. Please let me know.

RegistrationMagic
RegistrationMagic
6 years ago
Reply to  David Henley

Hi David,

With our latest version, conditions are supported on the File field. You may use it same as with the other fields now.

RegistrationMagic
RegistrationMagic
5 years ago

As of now, it is not possible to apply conditions on all the fields. We have made a note of your requirement and forwarded it to our planning team for review and analysis. Thank you for the feedback.