How to Build Conditional Webforms in Drupal 7

Building Conditional Webforms in Drupal 7

One of our OSTraining members asked us how to configure webforms with conditions.

We prepared this tutorial to show you how you can do just that on your Drupal 7 sites.

Step #1. Installing the Webform modules

For this tutorial, you will need the following Drupal modules:

Once you downloaded them, please go to these modules are make sure you have enabled them.

You should have the following module options ticked:

  • Chaos tools
  • Form builder
  • Form builder Webform UI
  • Token
  • Options element
  • Views
  • Views UI.

Under Structure > Content types, you will see that you now have the “Webform” content type. Review the default settings of this content type. I personally removed the “Published By” but this is my own personal preference.

Step #2. Building the Webform

Now that we have everything installed, let’s start building our webform.

  • Go to Content > Add Content and select “Webform”.
  • Give this form a title. Also, for ease of access, I am also going to assign it a menu link.
Creating a user experience feedback form

Now, using the form builder GUI, you can easily drag and drop the configuration elements that we need for this webform.

Choosing elements for a Drupal webform

In this example, I have created a “User experience feedback form” that will be asking for user’s Name, Email and to rate a service.

Choosing conditionals for a Drupal webform

We want to set up a condition, which will then trigger a feedback textarea if the ‘Not Happy’ option is selected. We want this textarea to display on the same page, so we will not use a page break for this form element.

Creating conditionals for a Drupal webform

Step #3. Testing the Webform

As we now have configured our webform, let’s make sure it works. While ‘Very Happy’ is set, you do not see the feedback textarea field:

Testing a Drupal webform

If, however, you select the ‘Not happy option’, then immediately the corresponding textarea field will show up.

Testing a Drupal webform conditional

As you have now learned in this tutorial, using conditionals in Drupal you can add many complex responses to your webforms, add some cool features to them and collect all the information you need.

Still have questions? Please submit them in the comments below.

Author

0 0 votes
Article Rating
Subscribe
Notify of
1 Comment
Oldest
Newest
Inline Feedbacks
View all comments
Lorenzo
Lorenzo
5 years ago

Hi
is there any way to specify that if text field A is not empty then text field B should contain the content of A?

1
0
Would love your thoughts, please comment.x
()
x