This video shows you how to create fields that only show if pre-defined criteria is met. (ie: if-then statements). You'll also learn how to create private fields that the user does not see, but administrators can view and edit.
- If we go back to the "Webform" tab, we can choose conditionals from the next menu.
- Here, we get a notice that says "There are conditional actions on this form. Add a new condition". So, I'll click the "+" sign
- Now we have some new options. I'll select "name" from the first drop-down
- Then we can say "if -Name is (John Doe) then hide -Birthday"
- Let's click "Save conditions", and check that out.
I will go back to the view tab and enter John Doe. And voila! when I move to the next field, the "Birthday" field disappears.
Back on the conditionals tab, if we change "Name" to "Email", our operators are similar, but if we change it to birthday it changes. This is because the birthday is a date field so it knows to show operators that are related to dates. If we select gender, we have more options that are specific to that question. The only thing that we cannot make conditional is the grid because there are multiple questions and answers in a grid.
This can also be done in reverse, so we can say something like: If Gender is Female, then show Annual Income. This will hide the "Annual Income" field by default, and only show it when the gender is set to "Female".
Currently, there is an issue with private fields and the Form Builder module. When you mark a field as private and save the form, the checkbox doesn't stay checked, even though the field is actually private. For now, I recommend that you disable the "Form Builder Webform UI" module to set private fields. Although, I do expect that the issue will be fixed eventually, so go ahead and try it. If the box stays checked, you should be good. If it magically un-checks itself when you save the form, disable the "Form Builder Webform UI" module while you set fields to private in order to make sure everything is set the way you want.
I'll show you how private fields work with the "Annual Income" field.
Create authenticated user to fill out the form
Since I'm the superuser of this site, I have access to all fields. So, I'm going to create a new authenticated user (Chelsea) and fill out the form as that user. And I'll give authenticated users the "Access own webform submissions" permission to further clarify private fields.
Disable Form Builder Webform UI and Make "Annual Income" field private
- The first thing I'll do is disable the "Form Builder Webform UI" module
- Edit the "Annual Income" field
- Scroll to the bottom and check the "Private" checkbox.
Fill out the form as an authenticated user
- Now, I'll fill out the form as "Chelsea". (You'll notice that she does not see the "Annual Income" field.)
- When I've completed the form, I'll click "Go back to the form"
- Then click "View your previous submissions
- And under "Operations" click "View". (There's an error at the top of the next page. It's already been reported, and can be ignored for now.)
Here, you'll notice that Chelsea cannot see the "Annual Income" field. However, when I view the submission as the site administrator (or any user that has the permission "Access all webform results") I am able to see the "Annual Income" field. I could also edit the field and enter data, if I wanted. (There's another issue here where prefixes and suffixes are duplicated. This has also been reported and is already being worked on.)
This may not be the most useful use of private fields, but it does show you how private fields behave. In part 14 I'll show you a good use of private fields when using a webform as a contact form.