| Drupal

Webform is a wonderful Drupal module.

We've an introduction to using Webform and a follow-up tutorial on how to send the form results to different email addresses.

It is possible to add Webforms to any content on your site. However, by default, you can't use the same form more than once. In this tutorial we'll show you how to re-use a webform whenever you need it.

In this example we'll add a "Contact the Organizer" form to all of the events you have listed a your site.

1) Install the modules

We're going to add need four modules for this task. Install and enable all four of these modules:

2) Create the content type

  • Go to Structure then Content types.
  • Set up a new content type.

3) Configure Webform and Webform Template

  • Go to Configuration, then Webform.
  • Choose Events as a "Webform-enabled content type".
  • Save that screen.
  • Go to Configuration then Webform Template settings.
  • Choose Events as the content type that webform templates can be applied to.
  • Choose Webform to act as your template to re-use.
  • Click Save configuration.

4) Create a webform

  • Go to Add content, then Webform.
  • Create the form you want to re-use.
  • Add the components you want to your webform.

5) Create the content

  • Go to Add content, then Events.
  • Scroll down to Webform and choose the Template you want to use.
  • Save the content type and it will look like the content below.

There one problem with the form as it is: it's not clearly labeled. The form allows people to contact the event organizer, but that's not mentioned anywhere.

We're going to use the Field Group module to fix that.

6) Adding a label to the webform

  • Go to Structure then Content types.
  • Click Edit in the Events row.
  • Click Manage Display.
  • Enter the label you want to show in the Add new group field.
  • Create a new field group.
  • Place Webform under the field group that you just created.
  • Click Save.
  • You'll now see that your webform has been clearly labeled.

Thanks to Cindy McCourt for the tip on this.

About the author

Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.