Drupal at Cal Poly

Cal Poly's Content Management System

Webform Conditional Example

Below is a short demonstration and tutorial of the webform conditionals feature.
You can try out the example used for this demonstration here.

  1. In this example, we will use the form shown below, titled "Conditional Example." 
    The form has one main question and different follow-up questions as its components.



     
  2. When published, the form looks like the figure below.


    Note how all of the follow-up questions (1-1, 1-2, 1-3A, and 1-3B) are shown, although some of them may be inapplicable to the user filling out this form, depending on his or her status. For example, Staff is not likely to be teaching a course for the term, but the question is still shown. 

    Although there are some potentially inapplicable questions for certain users, this form still "makes sense," because users can simply select "no" or put down random answer to the questions that do not apply to them. However, it may be problematic to use this approach for more complex and lengthy forms.

     
  3. At this point, we can go to to Conditionals menu to set up conditionals for this form.
    Conditionals menu​ item is located under Webform tab, next to Form Components.
    Clicking the icon will create a new condition you can apply to one or more questions.



     
  4. We set up a condition for Students so that the question 1-1 (regarding being a graduate student) is only asked if the user indicates that he or she is a Student. In the same manner, we also set up a condition for Faculties so that question 1-2 (regarding teaching a course) is only asked to users who identified their status as Faculty.


    Note that the resultant option is set as "show." When "show" option is selected, the questions selected as the resultant option (in this example, 1-1 and 1-2) will be hidden by default, and shown only when the set conditions are met.

    The opposite is true for "hide" option. When "hide" option is selected, the question selected as the resultant option will be shown by default, but will disappear as soon as the conditions are met for "hiding" that question.

     
  5. Now, we set up more complex conditionals that have multiple conditions required.
    If a user is either a Faculty or a Staff, we will ask the user if his or her department has any student assistants. However, we will only ask for the number of student assistants to users who identified themselves as Staff, because Faculties are less likely to know the number of student assistant their department has.


    Note that when you are setting up complex conditionals, you have a choice between "and" and "or" for combining multiple conditions. This follows the definition of "and" and "or" in computing. That is, if you select "and," all of your conditions will have to be satisfied for your conditional to take effect. If you select "or," only one (or more) out of all of the conditions needs to be satisfied for your conditional to take effect.

    In this example, a user's status may be either Faculty or Staff to satisfy the conditions to show question 1-3A, because those two conditions were combined with an "or." But to show question 1-3B, a user's status must be Staff, and the user must indicate that his or her department has student assistants in order to satisfy the conditions, because the two conditions were combined with an "and." Question 1-3B will remain hidden if the user indicates that his or her department does not have any student assistants.

     
  6. Once all the conditionals are set up, we must save them by clicking on "Save conditionals" button at the bottom of the page. This is a simple yet important step, as navigating away from conditionals page (by going to different menu or pressing the browser's back button) without saving will result in complete loss of all unsaved work.



     
  7. Now, the published form only shows the main question when it is first loaded.



     
  8. When a user selects "Student," only the relevant follow-up question (1-1) is displayed.



     
  9. When a user selects "Faculty," the form asks all relevant questions, except for the question regarding number of student assistants in his or her department (1-3B).


     
  10. When a user selects "Staff," the form shows only the follow-up question asking if his or her department has student assistants (1-3A). If the user selects "no," then the follow-up question regarding number of student assistants (1-3B) remains hidden. If there is no student assistant at the user's department, we know that the number of student assistants is 0, so there is no need to burden the user with a redundant question.



    However, if the user selects "yes," indicating that his or her department has student assistants, the follow-up question regarding the number of them is shown.


     

You can try out the example used for this demonstration here.

Related Content

Cal Poly's WCMS

Drupal Since 2009 Badge

Drupal has been Cal Poly's web content management system since 2009.

More About Drupal

Quick Start Guide

  • Quickstart Icon

    Learn
    Drupal Basics

  • Our Drupal 7 Quick Start Guide will help you get up and running in no time.

Start Drupalling!

User Management

  • User Management Icon

    Learn
    Users and Roles

  • Site admins can learn how to add/remove users, and what roles to grant their users.

User Management

Drupal Webforms

  • Webforms Icon

    Learn
    Webforms

  • This Webforms guide features a new interface to help you find the answer to all your questions quickly!

Webforms Guide

Mailing List

  • Mailing List Icon

    Follow
    Drupal Updates

  • Subscribe to our mailing list to stay up-to-date on Drupal news.

Subscribe