By james, 10 December, 2022
Advent Calendar door 10 containing Contact Storage

It’s day ten of the Drupal Advent Calendar. Wow, double digits!

I want to talk about collecting information from website users, and that often means putting some sort of form on your site, whether it’s a simple contact form or a complex multi-page survey.

Drupal has a built in module for handling this. It’s called Contact, and by default a new Drupal site has a Contact form active. This allows you to fill out a contact form and it will generate an email to inform the site admin.

It uses the Drupal form and fields system, which means that you can add any extra fields you want to your contact form, even ones defined by modules you’ve installed.

Contact form to be stored with Contact Storage, showing custom drop-down list field

You can also create additional forms, so it’s by no means limited to contact forms.

However, one of the limitations of the Contact module is that once the email has been sent, the data disappears from the site.

This is where today’s module, Contact Storage, comes in. It is a fairly simple module, it just treats each form as a storage entity, causing all submitted data to be stored in the site’s database.

You can then browse through submitted records, but you can also create Views to select the precise data you need and format it as required. Obviously care is needed to ensure you don’t expose personal data publicly when doing this.

Viewing the submitted contact forms

You can also export the form submissions, allowing you to use the data on external sites or applications. There are several ways to do this, but the easiest is probably to install the Contact Storage Export module. This adds an Export button to the form submissions page.

Contact Storage is a powerful addition to the basic Contact module, and can give you access to submitted form entries in a much more useful way.

It would be remiss to not also mention the Webform module when discussing Drupal forms. This is an extremely flexible and powerful module for setting up forms. It has a lot of very powerful features such as conditional fields (so field B only appears if a specific value was selected for field A).

However, if all you need is a simple form, it can be overkill, and personally I like to avoid unnecessary complexity when possible. When I need complex forms, I use Webform, but when I just need a contact form, or some simple forms that don’t need Webform’s advanced features, I’ll use Contact and Contact Storage.

So that’s 10 doors open. Come back tomorrow for door 11.

Advent Calendar with door 10 open containing the Contact Storage module

Comments

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.