Conditional logic in WordPress forms: show a field based on an answer

Written by

in

A good form only asks what it needs to. If someone says they are coming alone, there is no reason to ask for the names of their guests. Conditional logic is how a form adapts: a field, a whole step or an email appears only when the earlier answers call for it.

In Legba Form, conditional logic is part of the free version. Here is how it works and where it helps most.

How a rule is built

Select a field in the builder and open its Logic tab. A rule has three parts:

  • Show or hide this field;
  • when all or any of the conditions are met;
  • the conditions themselves: another field, an operator and a value.

The operators cover most situations: is, is not, contains, starts with, ends with, greater than, less than, empty and filled.

Example 1: a follow-up question

"How did you hear about us?" with the choices Friend, Social media, Other. Add a text field "Please tell us more" and show it only when the answer is Other. Everyone else never sees it.

Example 2: a different path for members

"Are you a member?" Yes or No. Show the membership number field when the answer is Yes, and the "Would you like to join?" field when it is No. One form now serves two groups without confusing either.

Example 3: an email only when it matters

Logic also works on emails. On a contact form with a Subject field, send a second notification to your treasurer only when the subject is Billing. The rest of the messages go to the general inbox as usual.

Rules cascade

When a field is hidden, it counts as empty. So if field B depends on field A, and field C depends on field B, hiding A hides everything that follows from it. You do not have to repeat conditions down the chain.

Hidden fields are also skipped by validation: a required field that is not shown never blocks the form.

Whole steps

In a multi-step form, a rule can apply to a full step. If nobody in the group has dietary needs, the step about meals is skipped and the progress indicator adjusts.

Keep it readable

Two habits make conditional forms easy to maintain:

  • Name your fields clearly, so that rules read like sentences.
  • Test every path in the preview, including the one where nothing extra appears.

Conditional logic on fields, steps and emails is free in Legba Form. Install it from WordPress.org. If you also need text that changes inside confirmations and emails, Legba Form Pro adds conditional text.

Comments

Leave a Reply

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