Last updated 9 December 2016. Created on 10 July 2012.
Edited by jrockowitz, Knarf31, bbujisic, alex.designworks. Log in to edit this page.

This page describes using conditionals in Webform 4.
This page is still incomplete and requires more information.

Conditionals were brought into Webform core starting version 4 (7.x-4.x).


Component - one of current webform's fields.
Conditional - single set of rules, rule collation type and targets.
Rule - single set of comparison source, value and type. Source is a component, value is a component's value and type is a comparison type (equal, not equal etc.).
Rule collation type - AND or OR. Defines how results from multiple rules conditions will be collated. AND - all rules must pass the condition, OR - only one rule must pass the condition.
Target-component which will be shown or hidden based on condition.

Creating a condition

  1. Before you begin, you need to create all the components involved in condition logic (both source and target components).
  2. Take a look at tabs above. In Webform page of the node, between Form components and E-mails, you will find a tab Conditionals. Hit it. You should end up in /node/[nid]/webform/conditionals page.
    If you cannot find the tab, make sure you are using Webform 7.x-4.x. If you updated from 7.x-3.x, try clearing caches.
  3. Click on + button to create condition. Choose the source (triggering component of condition), comparison type and value to create a condition. As a reaction, choose the field which will be shown or hidden.

Really simple example:

if -Choose your country- -is- -USA-
then -show- -Select your state-


Multiple Conditionals

Giving a components structure (conditional, not hierarchical)


conditionals rules need to be created for each combination of all parent values as rules to both show and hide components in hierarchy.
This allows to provide proper parent-child-grandchild cascading behavior.

I.e. for field Field111 there are 2 conditionals to be created:
1. Field 1 == 11 AND Field11 == 111 => SHOW Field111
2. Field 1 != 11 OR Field11 != 111 => HIDE Field111
NOTE: AND is used for all SHOW, and OR - for all HIDE rules.

Each time a component is hidden, it's value is reset. This works for cascaded hide as well (provided that HIDE rule exists).

Examples and best practice

Here is a list of examples on how to use conditionals.
This is a work in progress, please feel free to contribute.

Show a component dependent on the url

If you are using a webform on multiple nodes (e.g. in panels or in a block) you can use a conditional to show or hide specific components dependent on the current url. And here is how:

  1. create a hidden / private text component that will not be visible for the enduser
  2. give this component a default value by using a url token; e.g. the [current-page:url:args:last] token will get the last part of the url (e.g. /europe/germany/[cologne])
  3. Now this hidden component can be used on the conditionals tab

    if [hidden component] contains "cologne" then show [another field]

This will save you from creating multiple webforms which only differs in url specific components.

Looking for support? Visit the forums, or join #drupal-support in IRC.