Drupal Tutorials and Blog Posts

Reusing Drupal Webforms Across All Your Content

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.
tutuploadsmedia_1342815204480.png

3) Configure Webform and Webform Template

  • Go to Configuration, then Webform.
  • Choose Events as a "Webform-enabled content type".
tutuploadsmedia_1342815572628.png
  • 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.
tutuploadsmedia_1342815627042.png

4) Create a webform

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

5) Create the content

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

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.
tutuploadsmedia_1342816226026.png
  • Place Webform under the field group that you just created.
  • Click Save.
tutuploadsmedia_1342816252888.png
  • You'll now see that your webform has been clearly labeled.
tutuploadsmedia_1342816363944.png

Thanks to Cindy McCourt for the tip on this.

Comments

 
2pha
#1 2pha 2012-07-21 11:47

Wouldn't it be easier to select 'available as a block' in the advanced settings of the webform, then just place the block?
 
 
steve
#2 steve 2012-07-21 14:34

Hi 2pha

Yes, that's definitely one way to do it, although this technique does make it easier for the content creators to choose a form.
 
 
Kclarkson
#3 Kclarkson 2012-07-22 14:56

WOW !!! Thanks for writing this it is such a pain recreating forms.

Yes the block thing does work unless you want to add some fields that are specific to that node. Or you want the form to be identified with that node using arguments.

This method just saves so much time. Thanks
 
 
Nupur
#4 Nupur 2013-01-23 08:23

With use of webform tamplate, how can I send email which has all node specific variables ?

for example: can I send an email to admin with subject: "Registration for [event title]". ?
 
 
mazharoddin
#5 mazharoddin 2013-05-06 18:35

nice tutorial
 

Add comment


Security code
Refresh

blog-ad

Start Online Training

Members get access to all our video training. That's 1,142 training sessions in Joomla, Drupal, WordPress and Coding.

Latest Comments

The License for Our Tutorials

All of our tutorials are published under the Creative Commons Attribution-NonCommercial license. This means:

  • You can re-use these tutorials.
  • You can modify these tutorials.
  • You must link back to our original tutorial.
  • You can't use these tutorials commercially.

Click here to read the full license.

Open Source Training is not affiliated with or endorsed by the Joomla, WordPress or Drupal projects.
All product names and trademarks are the property of their respective owners.

Copyright 2013 Open Source Training, LLC. All rights reserved.