Goodbye Webform? Contact Forms Are In the Drupal 8 Core

Contact Forms Are In the Drupal 8 Core
In Drupal 7, if you wanted to create contact forms, you had to use a contributed module. Webform and Entityform were the most popular options.

Now in Drupal 8, forms are in core. Will be saying to goodbye to those popular Drupal 7 modules? Read on and find out …

Video on Contact forms in Drupal 8

The Contact module in Drupal 8

By default, Drupal 8 has the Contact module enabled, which wasn’t true in Drupal 7.

The Contact module has also been greatly enhanced. No longer does it simply provide a contact form on user profiles.

Drupal 8 provides two default contact forms: “Personal contact form” and “Website feedback.”

2 default Drupal contact forms

“Personal contact form” is the form that’s added to each user’s profile:

A Drupal 8 contact form

“Website feedback” is a generic website contact form. Drupal automatically provides a link to this form from the footer:

The Drupal 8 Website feedback form

Contact form settings

Each contact form has 2 main settings:

  • Recipients
  • Auto-reply

So you won’t see any of the more advanced Webform features such as redirecting users to particular URL after submission.

Drupal 8 contact form settings

Contact form fields and settings

In Drupal 8 you can add fields to forms, so you can create complex forms with no contributed modules.

Forms also have custom elements: such as “Sender email,””Recipient username,” and “Send copy to sender.” These can be arranged in the “Manage Display” tab of each form.

Drupal 8 Contact form fields

Storing contact form messages

So can we say goodbye to Webform and Entityform and rely entirely on the Drupal 8 core? No. Not yet.

The one key feature that’s missing with the Contact module is the ability to store messages sent through the forms.

This is odd, because Drupal 8 deals with contact messages as entities. You can add comments to them, for example. You just can’t see them!

To solve this problem. you’ll need a contributed module called Contact Storage. The author says they hope to have this in core for Drupal 8.1 and that would make a lot of sense, filling this functionality gap.

Drupal 8 contact storage module

After installing and enabling Contact Storage, you’ll see an addition tab with a list of messages:

Contact Storage module on a Drupal 8 site

Author

  • Steve Burge

    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.

0 0 votes
Article Rating
Subscribe
Notify of
61 Comments
Oldest
Newest
Inline Feedbacks
View all comments
larowlan
larowlan
8 years ago

As a maintainer of contact in core and contact_storage in contrib I want to point out that there are some things that webform is better suited to – that contact module cannot do.
These are

* Forms with lots of fields. Each field is a config object and this can increase the size of your fieldmap, as well as the number of tables. Webform stores its data in a single table, Field API stores fields in one-table per field. There is obviously a storage and performance implication there (This is the same issue with entityform in D7).

* Multipage forms (although fieldgroup in contrib might power this for contact module)

* Lots and lots of forms. Each contact form is a new entity-type bundle so adding lots is equivalent to adding lots of content types. (This is the same issue with entityform in D7).
That said, we have plans to bring elements of contact_storage to core in an 8.x point release (e.g. 8.1, 8.2) – please join the conversation on [url=https://www.drupal.org/node/2582955]https://www.drupal.org/node…[/url]
larowlan

steve
steve
8 years ago
Reply to  larowlan

Great, thanks indeed larowlan
That was very much the impression I got as a first time user of Contact. This will be great for basic forms, but power users will definitely need more.
Goodbye Webform? Nope, not yet.

Karl Kaufmann
Karl Kaufmann
8 years ago
Reply to  larowlan

Yes–I’d love to be moving some of my projects to D8, but Webform is a major piece of many of them (multipage at that). It’s one of the key issues holding back updating my projects at the moment.

Dave Hansen-Lange
Dave Hansen-Lange
8 years ago
Reply to  larowlan

Beyond just those technical differences, it’s important not to forget the usability differences. If your use case is to treat the forms as “content” that will be created by editors (e.g. surveys and polls), then Webform is definitely the better tool for the job. Its field creation UI is much less technical, and therefore easier to get working quickly, than Field UI.

Matt Saunders
Matt Saunders
8 years ago
Reply to  larowlan

Additionally to this, the ability to expose the form as a block is very important but doesn’t appear to have made its way to D8.

Jonathan Shaw
Jonathan Shaw
8 years ago
Reply to  Matt Saunders

See [url=https://www.drupal.org/node/2615112]https://www.drupal.org/node…[/url] for a patch developed by Acquia that allows attaching contact forms to entities (by entity reference). As blocks are fieldable entities, you could create a custom block and attach a form as the only field in that block.

Andriy Podanenko
Andriy Podanenko
8 years ago
Reply to  Jonathan Shaw

cool. Thank you tons for the link.

bobkruse23
bobkruse23
8 years ago

Just what the doctor ordered because there are currently no great solution for D8 at the moment. I didn’t know about contact storage so that might be a solution for me. eForm won’t be able to send emails until Rules is complete and Webform in D8 doesn’t really work yet. So Contact form (which I never ever used in D6 or D7), sounds like a good temp fix until webform is ready.

DrupalerSeven
DrupalerSeven
7 years ago
Reply to  bobkruse23

Unfortunately, 7 months after, the situation is the same… Currently I’m using eForm + custom module to send email o a couple of small projects, but I’m keeping D7 as main CMS for medium/big projects until D8 will be really ready.

chicken soup
chicken soup
8 years ago

Beyond creating simple contact forms, Webform is an extremely powerful tool. Its only flaw is that it doesn’t use Form API. Entityform could someday dethrone it, but for now Webform is the best thing around for building elaborate forms.

pjcdawkins
pjcdawkins
8 years ago
Reply to  chicken soup

Just to be pedantic: webform does use the Form API… it doesn’t use the Field API. For that reason, if you have many different forms and/or many fields, it’s much lighter to use webform than entityform.

chicken soup
chicken soup
8 years ago
Reply to  pjcdawkins

Yup, you’re absolutely correct. Webform uses Form API, but not Field API. That’s a real drag though because it’s not fully compatible with Views. If you want to do anything custom with the submission data you’re pretty much on your own. That’s really the only major drawback though.

pepperstreet
8 years ago

Interesting and helpful article/comments! Many thanks for some clarification and background infos about technical differences.

tagmac
tagmac
8 years ago

I’m trying to migrate a D6 site to D8. D6 contact form used to have a “settings” page where I could paste some text info (contact information, phone etc). Can’t find anything like that in D8.

steve
steve
8 years ago
Reply to  tagmac

Those would be fields now in D8.

tagmac
tagmac
8 years ago
Reply to  steve

Well, fields render as input fields on the contact form page and I just need to put some predefined text above the form (street address, phone number, contact name etc). Some text intro above the form. Webform uses “html markup” [pseudo]fields for that. D6 uses one “settings” textarea. Contacts module in D7 and D8 offers nothing I guess. Much like Entity forms. The simplest way is to put a content block on the contact page but I personally hate blocks made for one specific page.

David Simmons
David Simmons
8 years ago
Reply to  tagmac

I dislike this method as well. Is it still true that this is the only way to do this in D8? It seems that we should have a method to add predefined text to contact forms.

Matthew Oliveira
Matthew Oliveira
7 years ago
Reply to  David Simmons

You can also add a “Webform” content type, which has an entity reference field to a Contact form, which you set to Render as entity. Then you could have a Body field as well as the ER, which would give you a way to add text before the form. Not a great solution I know, but it works.

susanne
susanne
8 years ago

Hi i did my first site with Drupal 8 and i am really glad about the built in contactform , problem is it dosn t send mails i get both messages mail was send and mail couldn t be send and the mail is definitifly not sended . i did many tests and allways its the same result. Would be happy if someone can tell me how i can fix this. Thanks a lot Susanne

lilbebel
lilbebel
7 years ago

Hi there, is it possible to style the auto reply message? I’d like to add a company logo for example or tokens. Thanks.

Aghiad Yazji
Aghiad Yazji
7 years ago
Reply to  lilbebel

I’d like to do the same, have you found any solution?

Bolleddula Sambasiva Rao
Bolleddula Sambasiva Rao
7 years ago

Can I attach contact form to a node?

Matthew Oliveira
Matthew Oliveira
7 years ago

You can by adding an entity reference field.

Bolleddula Sambasiva Rao
Bolleddula Sambasiva Rao
7 years ago

Thank you..

Klemens Forster
Klemens Forster
7 years ago

Is there a way to modify the emails sent by D8 contact form? The mails look very ugly and I wonder if there is a twig-template for the mails. Would be nice to hear from you.

steve
steve
7 years ago

@klemensforster My guess is you may need a similar approach to Drupal 7 [url=https://www.ostraining.com/blog/drupal/html-emails-from-drupal-webform/]https://www.ostraining.com/…[/url]

Klemens Forster
Klemens Forster
7 years ago
Reply to  steve

Yeah, but there are no E-Mail Settings for Drupal Contact Forms. So I can’t modify the template. Any other idea?

Jorge Díaz
Jorge Díaz
7 years ago

This is what you were looking for:

[code]
hook_mail_alter(&$message)
[/code]

You can switch to get the form you need:

[code]
(…)
switch ($message[‘id’]) {
case ‘contact’: (…)
case ‘node_insert’: (…)
}
(…)
[/code]

And you can edit the body of the message:

[code]
$message[‘body’][] …
[/code]

The complete API Reference: [url=https://api.drupal.org/api/drupal/core!core.api.php/function/hook_mail_alter/8]https://api.drupal.org/api/…[/url]
Saludos!!!

Klemens Forster
Klemens Forster
7 years ago
Reply to  Jorge Díaz

Looks good. But I just tried to use the MYTHEME_mail_alter() function. It doesn’t seem to do anything. Do mails ignore hooks in the MYTHEME.theme file? Would be very annoying. Do I have to code a custom module, just to alter the mails sent?

Andrew Wasson
Andrew Wasson
7 years ago

You’ll need to build a small plugin module to override the email formatting. I did some playing around with it myself a few months ago but was only successful in tripping out all of the formatting. I’m also looking to improve Contact Form formatting.

london
london
7 years ago

Did anyone find an easy way of theming the contact form mail?
Or can anyone give me a link to the small module to override the mail formatting?

Rick_P
Rick_P
7 years ago

I sure wish I would have found this post before I built a site in Drupal 8 because the lack of webform is a bit of a deal breaker for me. The built in contact form not only doesn’t store submissions, you can’t add a body field either, making it impossible to have a custom message above the form.
I installed the Dev version of webform but got php errors when I started building a form, I guess it’s not quite ready for prime time.

daniel-pickering
7 years ago
Reply to  Rick_P

Hi Rich you could assign some content to a block region and have it only show on the form page if you want to provide information for the form. They have come along way and we have a few sub form modules that make it better now too.

Andrew Wasson
Andrew Wasson
7 years ago
Reply to  Rick_P

Hi Rick,

As Daniel Pickering states you can place your custom message content in a custom block and assign it specifically to the contact form in the content area. To gain additional features like storing/exporting submissions, have a look at the the Contact Storage module.

Rick_P
Rick_P
7 years ago
Reply to  Andrew Wasson

Andrew and Daniel, thanks so much for the hot tips. Not only did the clever work around do the trick, I installed the new eForm module, which is the D8 replacement for EntityForm. I got a PHP error from it when I created my first form type but the error wasn’t fatal and I was able to continue generating the form. So now I have the best of all scenarios, I have my text a the top, I have a robust form that sends emails, stores the data, and since it uses Drupal entities, I can do all kinds of things like create a View to display submitted data. I clearly got my cake and got to eat it too. ~Rick

DrupalerSeven
DrupalerSeven
7 years ago
Reply to  Rick_P

Hi Rick, I’ve not understand your message, are you using eForm? How does it send emails?

Rick_P
Rick_P
7 years ago
Reply to  DrupalerSeven

I apologize, I did say that it sends email but I was wrong, it does not. I’m working on using the Rules module to send emails but haven’t finished it yet.

daniel-pickering
7 years ago
Reply to  Rick_P

Rules are still in alpha but I imagine they are very close to being officially stable soon.

mabho
mabho
7 years ago

It is worth mentioning that webform has some handy additional features, like the ability to limit the number of form submissions, both per user and per node form. That way, I can set, for example, a simple course subscription form that will stop getting new inputs when the number of available slots are taken. Also, the fact that a webform is linked to a given node, with all the possible configurations applied on each node form instance individually, gives admins flexibility. Webform’s approach is different from that of the core contact form module on Drupal 8 and it has some advantages. It would be great to see it ported to Drupal 8.

Doc Kodam
Doc Kodam
7 years ago

Oct 2016
1. Webform will not have port to D8 and eForm is abandoned.

2. Best alternatives in this moment: Contact Storage + Contact Form(Core) or YAML Form.

steve
steve
7 years ago
Reply to  Doc Kodam

Thanks @dockodam I think you’re right on both points. This post may need an update.

Doc Kodam
Doc Kodam
7 years ago
Reply to  Doc Kodam

As of Jan2017, YamlForm now is “Webform 8.x-5.x release” (It is the exact same code base).
Best alternatives in this moment(D8): Contact Storage + Contact Form(Core) or WebForm 8.x-5.x

Gerry
Gerry
7 years ago

Is it possible to have a drop down menu for recipients so a person submitting a form can contact a specific recipient. This functionality is available in Webform.

Gerry
Gerry
7 years ago
Reply to  Gerry

I found the solution in the last comment5 here

[url=http://drupal.stackexchange.com/questions/212820/contact-forms-change-recipient-address-dynamically-d8/213211]http://drupal.stackexchange…[/url]

Suhrit
Suhrit
7 years ago

I can not able to install the contact storage module. It is saying “Token module is missing”.

steve
steve
7 years ago
Reply to  Suhrit

Install the Token module … that should solve the issue

Suhrit
Suhrit
7 years ago
Reply to  steve

Thanks. Can you please tell me the solution of other issue??

Suhrit
Suhrit
7 years ago

I have created a custom contact form like as the video is showing. Then I installed the captcha module and the form is showing good on the site [url=http://webappdesigns.com/projects/maxons_new/contact/apply_for_a_job]http://webappdesigns.com/pr…[/url] , But when we submitted this form I have got the following error –

[urlcomment image]https://uploads.disquscdn.c…[/url]

Can any one resolved such error message? If so please reply right solution. Thanks.

Suhrit
Suhrit
7 years ago

[urlcomment image]https://uploads.disquscdn.c…[/url]

Chen
Chen
7 years ago

Hello Steve, thank you for your article! I was wondering if there is a way to update the stored message programmatically? If it was a node I think I can do:
$node = Node::load($nid);

$node->body->value = ‘some new value’;

$node->save();
Is there an equivalent method for updating a stored message? Many thanks!
Chen

steve
steve
7 years ago
Reply to  Chen

Hi Chen. It might be worth taking a look at how this module does it [url=https://www.drupal.org/project/contact_storage]https://www.drupal.org/proj…[/url]

Seven_Six_Two
Seven_Six_Two
7 years ago

There’s some great info here. Where does everyone sit currently, at the start of 2017? I am looking for a form solution where a user clicks on a link to a one-time URL, and can fill out the form once. There was a module for D7, which I might have to use, but I was wondering if there’s a special D8 way?

steve
steve
7 years ago
Reply to  Seven_Six_Two

Webform may be making a revival: [url=https://www.drupal.org/project/webform]https://www.drupal.org/proj…[/url] Or to be more accurate, they took another module and renamed it “Webform”

Fred Baltus
Fred Baltus
6 years ago
Reply to  steve

Hi, I installed Webform 8.x-5.0-beta13 in my production environment. But when I select a few modules of it and install it, the site crashes….
I had a lot of work, to restore the site. How are other experiences?

said elfazni
said elfazni
7 years ago

Interesting article, yes contact and constate_storage are a great combination but even better is the webform module beacause it’s inspired from the user experience, it allows to buid forms, collects data, download the results and more other features.

Nowadays module yamlform asks users to download and install Webform 8.x-5.x or migrate to webform. [url=https://www.drupal.org/project/yamlform]https://www.drupal.org/proj…[/url].

The main thing to keep in mind though is to use what will best suit your need.

gaurav
gaurav
7 years ago

i had issue contact form auto save last name and email how to flush this

Maydi
Maydi
6 years ago

Hi, Steve. How to refer a contact form to field. I want refer a form to my paragraph type..

Thank you!

Kris
Kris
4 years ago

Hi!
How add contact form with shortcode help. I want add contact form to other  site. Footer and contact site dont interrest me. Thx for help.

Doug
Doug
4 years ago

I’m having issue with contact form. Currently the reply to is the email of site; therefore the from and the reply to are the same? I would like the authenticated and the ananymous email to be in the reply to field when reply to contact submission. Is there a setting or module to help with this. P.S. The anonymous email is in the submission body but the authenticated is only the username and not the email.

maonj
maonj
3 years ago

How can i put a google map on top of contact form(Website feedback form).

mikall
3 years ago
Reply to  maonj

See if this [url=https://www.ostraining.com/blog/drupal/static-google-maps-drupa]blog post[/url] helps any.

61
0
Would love your thoughts, please comment.x
()
x