Skip to content
crispforms

Conditional logic without the spaghetti

Branching makes a long form feel short. Done carelessly it makes a form nobody can edit six months later, including you.

· 9 min read · 1,913 words

Share

Conditional logic is the feature that separates a form from a questionnaire. Ask somebody whether they are a new or existing customer and then show them only the questions that apply, and a twenty-question form becomes an eight-question one without losing anything.

It is also the feature most likely to produce something unmaintainable. Rules accumulate, each added for a good reason on the day, and eighteen months later there is a form that works, that nobody understands, and that everybody is afraid to touch.

The difference between the two outcomes is almost entirely about structure rather than about how clever the rules are. A form with forty simple rules organised around one idea is easy. A form with nine rules that interact is not.

Branch on one thing

The single most useful discipline is to pick one question that determines the shape of the form and branch on that, rather than adding conditions wherever they seem locally sensible.

Usually there is an obvious candidate. Which service do you want. Are you booking for yourself or someone else. Is this a new project or an existing one. That question goes near the top, it drives the structure, and everything downstream depends on it and not on each other.

The result is a form you can draw on a napkin, which is the real test. If you cannot sketch the paths through your form in thirty seconds, neither can the person who has to change it next year, and that person is probably you with a worse memory.

If you cannot sketch the paths through your form on a napkin, it is already too complicated.

Show and hide, not jump

Most tools offer two mechanisms that look similar and behave very differently. Showing or hiding a question based on an answer is local and composable. Jumping from one page to another is global and order-dependent.

Prefer showing and hiding wherever it will do. A hidden question is simply absent, the rest of the form is unaffected, and removing the rule later restores the original behaviour exactly. Jumps create a graph, and graphs develop unreachable nodes, accidental loops, and pages that can only be reached by one path that somebody has since deleted.

Jumps earn their place when whole sections differ, such as a business path and a consumer path with little overlap. Use them at the section level and use show and hide within sections, and the form stays legible.

The hidden-required trap

The most common bug in conditional forms is a question that is required and hidden at the same time. The person cannot see it, cannot answer it, and cannot submit, and the error message points at something that is not on the screen.

Good tools handle this by ignoring validation on hidden fields. Not all do, and the ones that do not produce a form that works perfectly for the path you tested and traps everybody on the path you did not.

The habit that prevents it is to walk every path before publishing rather than testing the happy one. If your form has four branches, submit it four times. This takes five minutes and it is the only reliable way to catch this class of problem, because it never shows up in the editor.

Rules that depend on rules

The point where a form becomes genuinely hard to reason about is when a condition depends on an answer to a question that is itself conditional. Show question nine if question seven is yes, where question seven only appears if question three was no.

Each rule is simple. The combination is not, and the number of states grows faster than anybody's ability to hold them. Two levels of this is manageable. Three is where people stop being able to predict what their own form does.

If you find yourself at three, the honest answer is usually that you have two forms wearing a trench coat. Splitting them is less work than it sounds and produces something that can be changed without fear, which is worth more than the elegance of keeping everything in one place.

Write the rules down outside the tool

This sounds like bureaucracy and it takes four minutes. Before building, write the branching in plain sentences in a document, and keep it next to the form.

If they choose repair, ask about the fault and the model. If they choose installation, ask about the property and access. If they choose either and the date is within a week, show the urgent surcharge notice. That is the whole design, it is readable by anybody, and it survives the person who built it leaving.

It also catches design problems before they become editing problems. Writing the rules out is when you notice that two branches ask almost the same three questions, which is the moment to merge them rather than after both have been built.

Do not hide the price

A specific misuse worth calling out. Logic is sometimes used to hide the cost of an option until the person has committed to it, on the theory that they will be further in and less likely to leave.

They will be further in and they will leave anyway, and they will leave with a worse opinion of the business than if they had seen the number up front. Price revealed late reads as a trick regardless of whether one was intended.

Use logic to remove irrelevant questions, not to sequence information strategically. The first makes a form feel considerate. The second makes it feel like a negotiation, and people are very good at detecting the difference.

Keep the data shape stable

Branching creates an operational problem downstream that rarely gets thought about at design time. If different people answer different questions, your responses have different shapes, and anything reading them has to cope.

A spreadsheet of submissions from a heavily branched form is mostly empty cells, and a report built on it breaks the first time somebody adds a branch. If you feed submissions into another system, that system needs to tolerate missing fields rather than treating absence as an error.

The mitigation is to keep a small set of questions that everybody answers, ideally including whatever you sort and report on, and let the branching happen around that core. Then your data has a stable spine regardless of the path.

Signs the form has outgrown its logic

There are reliable symptoms, and noticing them early is much cheaper than noticing them during an outage.

  • You are afraid to edit it, or you copy it before changing anything.
  • Nobody can say with confidence what a given person will see.
  • There is a question that exists only to drive logic and is never read.
  • A rule references a question that was renamed and nobody is sure it still fires.
  • The same information is asked twice on different branches, in slightly different words.
  • Testing a change means submitting the form more than five times.

Cleaning one up

If you have inherited a form in this state, resist the urge to rebuild it from scratch, because the rules encode decisions nobody remembers making and some of them matter.

Instead, map it. Go through every rule and write it as a sentence, which produces the document that should have existed. Half the time you will find rules that contradict each other, rules that can never fire, and two branches doing the same thing.

Then delete rather than restructure. Removing an unreachable branch and merging two near-identical paths usually takes a complicated form back to a comprehensible one without changing what anybody experiences, and it is far safer than a rewrite.

Logic on the confirmation too

One underused application. The page somebody sees after submitting is usually the same for everybody, and it is one of the few places where branching costs nothing and helps a lot.

Somebody who chose an urgent repair should see different next steps from somebody who asked about an annual service. One needs a phone number and a timescale. The other needs a reassuring note about when to expect a reply and perhaps something to read in the meantime.

This is the cheapest personalisation available to a small business, it requires no integration, and it lands at the moment of highest attention. Most forms waste it entirely, which is a separate article's worth of missed opportunity.

Naming matters more than it should

Rules reference questions, and in most tools they reference them by whatever the question is called. Rename the question and the rule either breaks silently or starts pointing at something nobody intended.

This is why forms that have been edited by several people over two years tend to have at least one rule that does nothing. It fired correctly until somebody tidied up the wording of question six, and nobody noticed because the failure is invisible from the editor and only shows up as a question that stopped appearing.

The habit that avoids it is to settle the wording before building the logic, and to re-walk the affected paths any time you rename anything. It is a small discipline and it prevents the single most annoying category of bug in conditional forms, which is the one where the form used to work.

Logic is not validation

These get confused regularly and they solve different problems. Logic decides what somebody sees. Validation decides whether what they typed is acceptable. Using one to do the other job produces forms that behave oddly.

The common version is trying to enforce a rule by hiding a field. If an option should not be selectable when an earlier answer was a particular value, removing the option is usually better than hiding a downstream question, because the person never forms the wrong intention in the first place.

The reverse also happens, where validation is used to communicate something logic should have handled. An error saying this service is not available in your area, shown after somebody has filled in nine fields, is a branch that should have happened at question two.

Test the paths nobody takes

Every branched form has a path that almost nobody uses, and it is invariably the one that is broken. It was built last, tested least, and has not been looked at since.

The cheap safeguard is to keep a list of the paths and submit each one whenever you make a structural change. For a form with four branches that is four submissions and about five minutes, and it catches the hidden-required trap, the renamed-question trap and the unreachable-page trap all at once.

If your tool lets you preview a specific path, use it, but do not let it replace a real submission. Previews frequently skip validation and always skip whatever happens after submit, and after submit is where the expensive failures live.

How much is too much

A rough working limit for a form one person maintains is around a dozen rules organised around a single branching question, with no rule depending on a conditional answer more than one level deep.

Past that, the form is still possible and it stops being casually editable, which matters because the forms that earn their keep are the ones that get adjusted. A form nobody dares change slowly becomes wrong.

When you cross the line, split rather than simplify. Two forms, each obvious, beat one form that is technically impressive and practically frozen. Nobody has ever regretted having two clear forms.

logicforms
Share

Build a form that people finish

Free, with the per-question drop-off analytics this piece keeps going on about.

Start building free