| Drupal

How to Add Drupal Webforms to Content Types

An OSTraining member asked us if it was possible to connect Webforms to their content.

I can imagine a lot of use-cases for this. For example, if you have an "Events" content type, you might want a form so visitors can contact the event organizer. Or if you have a "Business" content type, it might be useful for people to contact the business.

This can be done thanks to a module called "Webform Extra Field" and in this tutorial I'll show you how.

Step #1. Install the modules

You'll need to install and enabled 3 modules to follow this tutorial:

Step #2. Create your webform

Go to Structure > Webforms. The Webform module will provide a default "Contact" form but you can also create your own webform here.

created webforms

Step #3. Add the field

  • Go to Structure > Content types.
  • Click "Manage fields" for the content type you want to connect to your Webform. For example, choose the "Article" content type.
  • Choose the "Webform" field type:

add webform field

  • After clicking to the second page of settings, choose your Webform from the dropdown list:

webform field settings

  • You can also configure the default settings for the form. If you have the Token module installed, you can prepopulate the fields in the Webform:

webform settings

Step #4. Create the content

Once you have created your field, go to Content > Add content. You can create the content as you normally would, but there will now be a contact form automatically attached to your published content.

webform node

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.