Contact Form 7 one of the best contact form plugins for WordPress easy to use and customize, but there are certain caveats, one such thing is adding conditional logic. It should be assisted with either Code or Third-party Plugin. Let’s consider you want to create a form that accepts user input and display related option/field only when certain conditions are met. So how do you add that conditional logic to the form without actually editing the form through code?
For Example, A user to register with a Fitness center is supposed to select the Time slot. Based on the gender selection the slot has to be displayed.
We don’t want to make our hands dirty with code, let’s do it using a plugin.
Install Conditional fields for contact form 7 plugin from a WordPress repository. Installing the plugin enables an additional tab Conditional fields.
Edit your CF7 form, you see an additional tag named “Conditional fields Group”. Now, click on Conditional fields group tag and generate a group tag.
The group tag should have a valid and unique name, in order to prevent conflicts and then insert the tag in the form.
Now the Conditional group field tag is inserted
Let the part of Contact form that you would like to show and hide based on some conditions, be inserted between these group tags.
Everything you put between the start and end tag will be hidden by default, so to make it appear on your form, Condition rule in the Conditional Fields tab is needed.
Save Your Form for the created fields and groups to show up in the Conditional Fields tab.
The rules to display each group based on the user selection is done from the “Conditional fields” tab.
Ensure the Value entered has its correct spelling, The Value field is Case Sensitive.
Save the Contact form and WE ARE DONE!
The working example