Category Archives: Systems

Developing Conditional Fields for Content Creation and Form Management

Greetings – It’s the Holidays at TIS, and that means a room full of decorations, off-tune seasonal music, and website development!

At UT Libraries, we have a robust amount of different content, and deal with a large community of engaged active website users. One thing we actively have to consider all year long is how to make thorough webforms and other data entry.

To make a holiday example: If you are writing the Libraries for research information on decorations, there’s a chance we’d like to set up a form that thoroughly investigates every type of decoration, color, kind of decor, etc, so that your inquiry is best answered. Regrettably, this can lead to a lengthy and intimidating webform that shows each option all at once, filling up a page with text.

To help address this, we’re currently developing new content strategies using conditional fields. In Drupal, we’re using two modules, Conditional Fields and Webform Conditional. (Any Drupal readers here will want to know that we’re on D7, and Webform 3)

Both of these modules add a great amount of flexibility to cleaning up a content form or a webform, so that a user is not bombarded by a huge amount of text showing EVERY detail of information needed to complete an form submission. Instead, they allow for a series of initial questions to be answered, which will then reveal appropriate additional questions.

Step one: Using this with Webforms

To take our hypothetical example of writing for Holiday Decorations advice. (caveat: We do not offer Holiday Decorations advice at UT Libraries!) – But a non conditional webform might display like this:

Type of Decoration: (Red, Blue, Neither)
If you chose Red, is Orange okay? (Yes, No)
Do you Have another Color you would like? (fill in the blank)

This can sprawl out into all sorts of fussy questions. Perhaps there could be a nicer way, where only the first of these three questions appeared, with follow-up questions based on how you answered?

Now, if this form were modified to be conditional, that lighter looking form would be attainable.

So, instead of seeing all three questions below, a user would only be asked “Type of Decoration” first.

If they pick “Red” then the question about “Is Orange okay” would then appear. And if they picked “Neither”, then they would be offered the question “Do You Have another Color you would like?”

Technical Jargon: The way this works is you identify dependancies with fields, so that one field will only display if a value of another field is triggered. For Webforms, this is fairly easy to figure out – a new field setting called “Conditional Rules” is added to the options for each field you create. There, when setting a condition for a hidden entry (Like “Is Orange Okay”) you select a component and a value for this to display if the other Field “Pick a Color” has a chosen value for “Red”, which is likely “1”.

Step Two: Using this with content types

Conditional Fields work instead with internal content type forms, offers even more workflow options – particularly for large organizations that often have sprawling content items addressing any number of fields, decisions, tabs. You can modify your existing forms to instead just reveal the first one or two questions about a piece of content, and then reveal other items, as needed – based on what is answered. Prior to Conditional Fields, the workflow solution would instead be to group items into a series of tabbed off sections and indicate Required Fields that were common to everyone. A great video that explains this, including how to customize these features can be found on Youtube, courtesy the always-useful Daily Dose of Drupal.

Like a holiday tree, we at UT Libraries we’re excited about being able to trim down our content forms (ho-ho-ho! sorry about the tree pun!) And we hope you enjoy idea for managing your own content forms and webforms in Drupal.