How to Use Conditional Logic in WordPress Forms

A form that asks everyone the same questions, no matter what they actually need, wastes everyone’s time. A first time visitor gets buried in fields meant for returning customers. A simple support request sits next to fields meant for a full project quote. The visitor scrolls, gets confused, and often just leaves before finishing.

The fix isn’t a shorter form. It’s a smarter one, a form that only shows what’s relevant based on what someone has already told you.

That’s conditional logic: a way to make a WordPress form react to the answers it already has. This guide covers what conditional logic in WordPress forms actually looks like, then walks through five ways to put it to work: showing and hiding fields, redirecting visitors after they submit, routing emails to the right inbox, setting values automatically, and stacking conditions together for more advanced builds.

What you’ll need

To follow along, you’ll need Ninja Forms (free) and the Conditional Logic add-on (included with memberships or available as a standalone add-on). Conditional Logic is a separate plugin from Ninja Forms core, so install and activate it before you start. Until it’s active, none of the settings covered below will appear in your form builder.

What is conditional logic in WordPress forms?

Conditional logic is a rule that changes how your form behaves based on an answer someone already gave. Every rule follows the same shape: when this answer is given, then do this, otherwise do that. Ninja Forms uses that same rule to control four different things: which fields are visible, where a visitor lands after submitting, who gets notified by email, and what value a field quietly holds.

Because it’s one mechanism reused four ways, you only have to learn the pattern once. The rest of this guide teaches it through the most common use case, showing and hiding fields, then shows you the same pattern applied to redirects, email routing, and field values.

Show or hide form fields based on a previous answer

This is the most common use of conditional logic: a field stays hidden until a specific answer makes it relevant, then appears automatically, with no page reload. A project inquiry form, for example, can hide its budget field until someone selects “a brand new website build,” and hide it again if they change their answer.

Each condition rule lives in your form’s own settings, not on the individual field. To find it:

  1. Open your form and click into the Advanced tab.
  2. Click into Conditional Logic from there.
Ninja Forms builder with the Advanced tab active and the Conditional Logic tile indicated among the Additional Settings tiles.

Click Add New Condition to create a rule. Every rule has three parts:

  • When, one or more comparisons against a field’s answer, using comparators like Equals, Does Not Equal, or Contains
  • Do, what happens when the When is true
  • If the Condition Is Not Met, what happens when it’s false

For show and hide, set the Do action to Show Field, and under If the Condition Is Not Met, set it to Hide Field, both targeting the same field. One rule handles both directions: the field appears when the condition is true and disappears again when it isn’t. If a single rule needs more than one comparison, combine them with the And or Or connector.

A Ninja Forms conditional logic rule with a When comparison on the project type field, a Do action set to Show Field targeting the Budget Range field, and an If the Condition Is Not Met action set to Hide Field.

A field hidden by a condition isn’t just visually hidden. Ninja Forms removes it from the page entirely until the condition is met again. That’s good news for accuracy: a hidden field’s old value never gets submitted with the form, because the field isn’t there to submit. It also means that if you ever troubleshoot with your browser’s developer tools, a hidden field genuinely will not show up on the page, so don’t waste time hunting for it.

One thing worth checking before you publish: if the field driving your condition is a dropdown with no blank placeholder option, browsers automatically select the first choice when the page loads, and Ninja Forms treats that as a real answer immediately. If “a brand new website build” happens to be the first option in the list, your budget field will already be visible the moment the page loads, before anyone has touched anything. Add a blank “Select one” option as the first choice in the trigger field to avoid this, or make sure whichever option sits first is one where showing the extra field right away isn’t confusing.

Give Ninja Forms a try today!

Ninja Forms is free! Optional premium features available with any membership.

Send visitors to different places after they submit

The same when/then rule that shows and hides fields can also control where someone lands after they submit, called a conditional redirect. A form can send one type of lead straight to a scheduling page and let everyone else land on a simple thank you message, all from a single form.

Conditions on an action work almost the same way, with one difference: instead of Do and If the Condition Is Not Met, you choose Process This or Don’t Process This, paired with a single When list. If that list has more than one comparison, choose All (every comparison must match) or Any (just one has to).

To make a redirect conditional, open the Emails & Actions tab, click into your Redirect action, and find its Conditional Logic section. Set it to Process This only When the answer you want to trigger it matches, and leave every other submission to fall through to your form’s default success message.

A Ninja Forms Redirect action's Conditional Logic section set to Process This only When the project type field equals a specific answer.

Email actions use this exact same Process This pattern, which means you can route different submissions to different inboxes without learning anything new.

Route the right submissions to the right inbox

Any Email action can be made conditional the same way as a redirect: Process This, When, and an All or Any connector. That means one form can notify your sales team about new project leads and your support team about existing accounts, instead of every submission landing in one shared inbox. Multiple conditional email actions can run on the same form and fire independently, so a submission that matches more than one condition can trigger more than one email.

This guide covers the setup surface. For a deeper walkthrough of routing submissions to different departments and building out multi-recipient logic, see our guide to sending conditional emails.

Set a field’s value automatically based on the answer

Conditional logic can also fill in a value nobody typed. The Change Value trigger, found in the same dropdown as Show Field and Hide Field, sets a target field to whatever text you specify when a condition matches. It’s commonly paired with a hidden field, so the value gets recorded on submission without ever appearing as an extra input for the visitor to notice.

A common example: a hidden “Priority” field that changes from “Standard” to “High” whenever someone selects “ASAP” as their timeline. The visitor never sees the field, but the value saved with their submission reflects it, giving your team an instant way to sort urgent requests without opening every entry. This kind of setup is often called a dynamic field: a field whose value updates automatically based on other answers, without the visitor typing anything into it directly.

Stack conditions for more advanced builds

Once you’re comfortable with a single condition, you can combine several into one rule for more specific outcomes. A client intake form, for example, might need to flag a request as urgent only when it’s both a brand new project and a rushed timeline, not either one alone.

To do that, add a second When comparison to the rule and join it with And. A rule that only fires when “project type equals new build” And “timeline equals rush” is more specific than either single condition rule alone, and when both are true, it takes effect on top of a simpler rule watching just one of those fields.

A Ninja Forms conditional logic rule with two When comparisons joined by And, one checking the project type field and one checking the timeline field.

One thing worth planning for once you start chaining conditions: a rule only re-evaluates when a field in its own When changes. If your specific two-condition rule sets a value and then one of those two answers changes back, the value it set will not automatically reset, because an If the Condition Is Not Met action was never given to that rule. The fix is simple: whenever a chained rule sets a value, give its If the Condition Is Not Met branch a matching reset action, so the field doesn’t hold onto a stale answer after someone changes their mind.

Nothing stops two different rules from targeting the same field, either. That’s useful once your form has several branching paths that all need to update the same summary or priority field from different directions.

One rule, applied everywhere

Every capability in this guide, showing and hiding fields, redirecting visitors, routing email, and setting values, runs on the same when/then rule. Start with one show/hide condition to get comfortable with the pattern, then reuse it wherever your form needs to do more than just collect answers.

Try Ninja Forms Today

Always free, with premium features available through our memberships.

33 Comments

  1. Thanks for this extensive documentation Quay, I’ll try this out definitely. However, I wish there would be a simplier appoach to show multiple fileds of the same rather than configuring each and every form field as a conditional statement.

    Just to show an example, I have a network of schools and the submit every year their list of graduates, sometimes this number is 40, 50. Currently using it this way would be an overhaul.

    1. Eric,

      Sure! Use an HTML field for each image you want to display, and write conditional statements that will show/hide the appropriate HTML field per the user selection. Should be pretty simple!

      Cheers,
      Quay

  2. Can you make a conditional form? For example:
    If “yes” selected, go to another form than if you don’t select, go to next normal page

  3. when field “xxx” is not empty than show field “yyy”
    when field “xxx” is empty than show field “yyy”

    is there a way to do this with textfields?

    1. Otto,

      Your example condition would always be true so “yyy” would always show since “xxx” would always be true in this instance.

  4. sorry my question was a bit unclear…
    I want to use a form with 10 single line textfields and the last 4 fields must only show up if the other are filled in.
    So is there a condition to check if a field is empty or not?

  5. Sorry, this is probably a dumb question, but here it comes anyway…
    Using the example in your article: if the user selects 3 friends, fills out all the details but changes it to 2 friends, does that mean the filled out fields for friend ‘3’ are still there but just hidden? And if so, will those values still be sent with the form submission or are hidden fields ignored?

    1. Not a dumb question at all! The fields for friend 3 would be hidden when they switch back to 2 friends. Fields that are conditionally hidden will not show a value in submissions.

      Cheers,
      Quay

  6. Can we make a condition whereby when the Sumbit Form Button is clicked, the results are taken to the next form?
    My first form doesnt include user details. SO after inputing the details I want in the first form, I want the results to be taken and printed on the second form page, where user will be presented with another form to input his personal details

  7. Definitely, a repeater field would be better. And conditional logic UI would better be in the field settings, not the form settings.

  8. Is there a way to then hide the unused fields from appearing in the PDF file that is created when we use the PDF submissions plugin so that the output PDF doesn’t show empty/unused fields? I hate to have our internal users have to scroll past those sections when reviewing documents. Professionalism is in the details.

    1. Please disregard, this was answered in another section (instead of {all_fields_table} I need to change it to {fields_table}).

  9. I have a form with conditional logic fields so that the user can bypass certain questions if they give a particular answer.
    Can I make all of the questions mandatory required fields as well as have the conditional rules??

    1. Hi Kaye,
      that is an excellent question! Required fields, if hidden, will not be treated as required. i.e. the form will still validate and submit. They will only cause the form to fail validation on submission if they are visible to the user.

      Instead of marking the field required in the form, you can set it to be required using conditional logic. Doing it this way removes the possibility that the user will be blocked from making their option.

  10. Hi,
    I want to build a contact form with Ninja forms, with the email address field only as a dynamic field. There is a thank you page after this contact form page, where the email address has to show op. Together with some text. Is this possible to make in the Ninja plugin without editing the code?

  11. This is great, however, I wish this could be set up with repeater groups, therefore we can create the name, email and phone field for guests and depending on the number of guests it’s the amount of field groups that will be shown.

    I have a situation where user’s need to fill in some birthday card information but they can buy 2, 3, 10, 20. I can’t manually set up fields for each birthday card because I don’t know how many will they need.

  12. Hi, I am using the Paypal Express plugin and Conditional Logic plugin and I want to be able to make the price change based on the city they say they are from. The city field is a select field, and I want the price for Lawrence to be $320, but Kansas City to be $380, etc. How can I make the price field change and be a field where the person filling out the form cannot edit that price? What kind of field does the price field need to be???

    1. Is there a way to lock a number field so that they cannot change that price number manually?

  13. Does the comparative value always need to be a hard-coded figure or can we use a variable here,
    e.g. can we do
    When value is Greater or equal to [$variable] then…

    1. Hi Nick,

      The comparative value will need to be hard-coded unless you are using a list field ( i.e., Select, Check, Radio ), in which case a list option will be provided as a choice for the comparator.

  14. Can conditional forms be used to show an alert based on the built in US state field if a certain state is not selected? I’ve tried various different ways to get it to work but I’m not having success. The Alert shouldn’t show up when the select box is in it’s default state of “- Select State -” , I only want the Alert html field to show after a user makes a selection and doesn’t pick a certain state.

    And I don’t want to have to include every invalid state in the logic, that would be a pain to enter with the interface as it currently is.

    I’ve tried this, where the if condition is a combination of two does not have selected conditions:
    When
    State Field does not have selected “-select state-”
    AND State field does not have selected “Texas”
    do
    html alert show field
    if the condition is not met
    html alert hide field

    But that doesn’t seem to work

    I’ve tried the OR version of that.

    When
    State Field Has Selected “-select state-”
    OR State field Has Selected “Texas”
    do
    html alert hide field
    if the condition is not met
    html alert show field

    How do I handle a default placeholder field like that?

  15. I also attempted to make use of calculated values to get this to work.

    Set the calc value for “- Select State – ” and “Texas” to 1, left the rest at 0.

    But for some reason the calculated variable set to that field never changes from 0. So I cannot use that to show and hide the field based on the the value being >= 1.

    And I also tried setting a hidden field as the control variable, but I cannot figure out a way to change that variable based on the value not being ” -Select State -” or “Texas”…

  16. Hi Josh
    Thanks for reaching out.
    Since your issue may take some time to sort out, can you please reach out to us via our contact form for support.
    Don’t forget to include a System Status report and an exported copy of the form having issues.
    Thanks!
    Mia

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.