By: Hashik
April 13 2018

How to Use Contact Storage with Contact Forms in your Drupal Website

You are reading this article, and you realize there is some technically wrong information. You want to inform me but without embarrassing me in the comments. I don’t think anyone will go to an extent to find my email id and then inform of the error. How do they do it? While not wasting around much time.

This is where contact forms come to rescue!

Having contact form improve the chances of people reaching out to you and the best part is thing is that you don’t disclose your mail id, thus reducing the spam emails. 

The scope of contact forms is not limited to the above scenario I mentioned above. You might be a freelancer, business owner or contract worker, having a contact form will make it easy for the people/ clients to reach you. The messages that are submitted through the contact forms (using contact form module) are sent to your configured mail. All you need to do is to check your inbox. 

Better, the module allows you to view the messages without having to leave your Drupal site. The messages are sent to your mail too but you can access them from your site as well, provided you are logged in.

Lets us know a little more about these modules and their backstory before installing and making use of them.

feedback form
An example of feedback form

Contact forms in Drupal8

In Drupal 7 to implement a contact form, we have to install separate modules, the most popular ones include Webform, or Entity form. In Drupal8 the Contact Forms module comes out of the box, As a matter of fact, when you first install Drupal 8 there is already two contact forms that are given as default, personal contact form, website feedback. Though Contact Forms are given out of the box and are easy to handle they have their cons compared to the popular module Webform I will mention a few here:

If forms are having many fields they are essentially adding many tables into the database. It’s not the case with Webform since they store everything in one table. The field API adds one table per each field. There is defiantly the question of optimization and space with choosing inbuilt contact over Web form. This problem persists with Entity form as well.

Multi-Page forms aren’t possible with contact module (but, you can achieve this by adding field group module alongside Contact).

Each form is considered as entity type adding a lot of forms is equivalent to adding many content types.

Now that we are aware of what a contact form is and learned a couple of things about contact module and it’s alternatives, I am going to show you a demo on how to create a contact form and to store it’s messages.

Setting up a custom contact form

In Druapl8 as mentioned above the contact module is in the core, no need to install it. Go to Structure > Contact forms > Add contact form you can see the default contact forms given by Drupal there.

selecting "add custom form"
Selecting "add custom form"

Fill the fields appropriately, all those fields are self-explanatory with hints/ documentation written below them and then hit Save. Label and Recipients are mandatory to fill.

Adding content information in the contact form
Adding content information in the contact form

You will be redirected to contact forms again if you aren't going to Structure > Contact form and click on Edit > Manage fields tab for the contact form you created to configure its fields and click on add field.

The messages submitted through contact form (using the module) are sent to your configured mail as well as your Drupal website. 

managing the contact field


adding custom field in the "manage field"
Adding custom field in the "manage field"

Select the type of field you want to add and select its label and click Save and Continue and next click Save Field Settings.

adding custom label
Adding custom label 

The page you next see is subjective to the field you choose chose appropriate settings and hit Save settings.

adding custom fields in the contact form
Adding custom fields in the contact form

Now, you’ll be redirected to the Manage Fields go to Manage form display if you want to change the order of the fields.

We have our form ready, now, if people send you a message it goes to my mail but if I want to read it from inside the Drupal site without leaving we can install the Contact Storage module.

Installing and setting up contact storage

A point to note is that the developers are planning on adding the Contact Storage to the core, check if you already got it, at the time of this article it is not added yet. 

Use the drush command below to install and enable the Contact Storage module 

drush en contact_storage -y

And to rebuild cache use

drush cache-rebuild 

First, you need to copy the path of the forum you want the messages to be stored, to copy it go to Structure > Contact forms and click on the form you created and copy its path in the URL bar.

You are done! Now we get the message in the Drupal site as well as a mail, let us test it;

testing the contact form
Testing the contact form

Now go to the Contact Storage module and click on Configure to see the message, you can go to your mail to see the message as well. 

Now your users can get in touch with you effortlessly. Having a contact form around in a website is always the best Idea more so when you don’t want to share your contact information and yet receive messages.

Drupal has got the module for just about everything, hope the devs come up with an ingenious idea to tackle irrelevant messages that users send via contact forms too. Most of the messages I get are spam, some of them are the constructive criticism though, despite these problems, it is good to have contact form around.