Introduction
Applying and testing conditional logic on forms can take a bit of trial and error.
You’ll need to embed your 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.)
You’ll do a lot of refreshing of this published/preview page while setting up an testing configuration.
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
2 = All, Any or One
3 = Options include: Empty / Filled; Checked / Unchecked; Value is /Value is not
In this example, we can see that question 4 is set to be visible if the answer to question 3 is ‘Individual’. You can infer that there’s probably another conditional logic configuration set up on another question if the answer to question 3 is something else.
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 building the form or tool, it really helps a lot.
Plan your logic
People often set up a flowchart to map out the logic of a form or tool. I find it helpful to transfer this info a document to plan the numbering and the logic. 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, required | na |
5 What is your enquiry about? | Radios, required Responses only for | Visible if value is 4a |
5a Apples | If Q4 value is 4a and Q5 value is 5a email apples@vic.gov.au | |
5b Bananas | If Q4 value is 4a and Q5 value is 5b email bananas@vic.gov.au | |
5c Oranges | If Q4 value is 4a and Q5 value is 5c email oranges@vic.gov.au | |
6 What is your complaint about? | Radios, required | Visible if Q1 value is 1b |
6a Melbourne | If Q1 value is 1b and Q6 value is 6a email melbourne@vic.gov.au | |
6b Geelong | ||
6c Phillip Island |
Email handlers can have logic too
Refer to Create a Drupal webform - email notifications.
To add an email handler, go to Settings > Emails / Handlers.
On this example from the Email handers screen, you’ll see:
on the left are free-text notes on the conditons
in the middle is a summary of the settings, notably the ‘reply to’ address and the custom subject line
on the right you can see that conditions (logic) have been set
This was a complex setup with many different email addresses and logic that included specific responses to 3 questions.
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).