Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • progressively show questions or information

  • show different questions or information according to previous responses

Process

  • based on previous responses.

Pre-reading

This guide assumes you’re familiar with how to create a Drupal webform.

See our other articles on forms and privacy.

Process

What you need to know

As for all Drupal forms, you need to create the form and embed it in a Landing page in the CMS. Then you publish or preview that Landing page for testing. (Although there is a test function in Drupal forms, it’s more reliable to test on an SDP front end view.)

Applying and testing conditional logic on forms can take a fair bit of trial and error. You’ll do a lot of refreshing of this your published/preview page while setting up an and testing logic configuration.

You’ll need to embed your Drupal form in a Landing page in the CMS and publish or preview that Landing page for testing. (While there is a test function in Drupal forms, we prefer to test on a front end view.) Tip: It helps to have 2 browser windows open side by side - building the form in one and testing the preview in the other. Each time you make a change on the form’s logic, you hit refresh on the other screen to see if your change did what you expected or wanted it to do.

What you need to do

Follow this basic process:

  1. Plan your logic first (see below).

  2. Add all your questions and information in your form in the CMS first. .

  3. Progressively apply conditions and keep testing.

    • Hidden/visible logic can be applied on text fields

    . More specific
    • , not just on 'questions' (use the Advanced HTML element).

    • Specific logic is mainly used with radio and checkbox elements (e.g. Q2 is visible if the response to Q1 is 'no').

  4. Progressively apply conditions and keep testing.

...

Info

Tip: build screen

When you are in the Build mode on a webform, you can see if conditional logic has been applied to a question or piece of text by looking in the ‘Conditional’ column.

...

Conditional logic settings

When you’re in Edit mode of a form element (a question or piece of text), you’ll see a panel on the right of your screen. Click the ‘Conditions’ tab to apply settings.

...

From the screenshot above:

1 = State: Visible or Hidden (usually 'visible')

2 = All, Any or One (to add more than 1 element so that ‘all’ or ‘any’ are applicable, click the plus icon next to the element)

3 = Options include: Empty / Filled; Checked / Unchecked; Value is /Value is not

Numbering: Because you’re showing and hiding information and questions according to answers chosen on previous questions, it doesn’t make sense to number the questions on the final published form or tool. But while planning the logic and building the form or tool, it’s really useful. You can see on the table below how the numbering helps state the logic/conditions. And when you’re a lot when you might be trying to select items on a long dropdown.

...

Click Edit to add logic.

image-20240919-012002.pngImage Added

Plan your logic and create your test plan

People often set up a flowchart to map out the logic of a form or tool. I find it It's helpful to transfer this info all the information a document to plan the numbering and the logic.

This document can then be used as a test plan for your tester. You should always get other people to test your form thoroughly before you go live. You can create a share link of the page where you embedded the form for this.

Here’s an example:

Question / Text

Notes

Conditions / email handler

1 What is your full name?*

Text field, required

2 What is your email address?*

Email field, required

3 What is your phone number?

Phone number field (10 digits), not required

4 What type of enquiry do you have?

4a Question

4b Complaint

Radios, requiredna

5 What is your enquiry complaint about?

Radios, requiredResponses only for

Visible if Q4 value is 4a

5a Apples

If 4b

5a Melbourne

5b Geelong

5c Phillip Island

6 The next question (specifically for questions about Melbourne)

Visible if
Q4 value is 4a
and
Q5 value is 5a

email apples@vic.gov.au

5b Bananas

If 7 The next question (specifically for complaints about Melbourne)

Visible if
Q4 value is 4a4b
and
Q5 value is 5b

email bananas@vic.gov.au

5c Oranges

If 5a

8 The next question (specifically for complaints about Geelong)

Visible if
Q4 value is 4a4b
and
Q5 value is 5c

email oranges@vic.gov.au

6 5b

9 What is your complaint enquiry about?

Radios, required

Visible if Q4 value is 4b

6a Melbourne

6b Geelong

6c Phillip Island

7 The next question (specifically for questions about Melbourne)

Visible if 4a

Email handlers

Question + Melbourne

Complaint + Melbourne

If Q4 value is 4a
and

Q6 value is 6a

8 The next question (specifically for complaints about Melbourne)

Visible if Q5 value is 5a
then email melbourne-questions@vic.gov.au

If Q4 value is 4b
and Q5 value is 5a
then email melbourne-complaints@vic.gov.au

Email handlers

Question + Geelong

Complaint + Geelong

If Q4 value is 4b
and
Q6 Q5 value is 6a

9 The next question (specifically for complaints about Geelong)

Visible if 5b
then email geelong-questions@vic.gov.au

If Q4 value is 4b
and

Q6 value is 6b

...

Q5 value is 5b
then email geelong-complaints@vic.gov.au

How to use conditional logic settings: questions and text

When you’re in Edit mode of a form element (a question or piece of text), you’ll see a panel on the right of your screen. Click the ‘Conditions’ tab to apply settings.

...

From the screenshot above:

1 = State: Visible or Hidden (usually 'visible')

2 = All, Any or One (to add more than 1 element so that ‘all’ or ‘any’ are applicable, click the plus icon next to the element)

3 = Options include: Empty / Filled; Checked / Unchecked; Value is /Value is not

Info

Numbering: Because you’re showing and hiding information and questions according to answers chosen on previous questions, it doesn’t make sense to number the questions on the final published form or tool. But while planning and testing the logic and building the form or tool, it’s really useful. You can see on the table below how the numbering helps state the logic/conditions. It also helps when configuring logic and you need to select items on a long dropdown.

Conditional logic settings for email handlers

Refer to Create a Drupal webform - email notifications.

...

The State for email handlers is either Enabled or Disabled. The conditions required that all 3 elements needed to have the set value in order for the handler to take the specified action (i.e. send to the specified email address).

...

...

Hide the submit button

On the Settings tab of the form there’s a checkbox to disable xxxxIf you’re building a decision tool and don’t want the user to submit any responses you should hide the submit button.

To remove the default Submit button, xxxxxxxxxxclick on Edit and tick the Hide submit button checkbox.

...