Reader small image

You're reading from  Drupal 10 Masterclass

Product typeBook
Published inDec 2023
PublisherPackt
ISBN-139781837633104
Edition1st Edition
Tools
Concepts
Right arrow
Author (1)
Adam Bergstein
Adam Bergstein
author image
Adam Bergstein

Adam Bergstein is a product engineering leader and an architect. He has been a long-time Drupal community member, a routine speaker at Drupal community events around the globe, and provided keynotes for several events. He has maintained and contributed to many Drupal projects, including Password Policy, Taxonomy Menu, and more. Adam is the lead of Simplytest, a free service, and a project that offers Drupal community members testing sandboxes. He has also worked for both agencies building Drupal applications and Drupal service providers building Drupal-related products. He has led the Drupal Community Governance Task Force and is serving a term as a community board member of the Drupal Association.
Read more about Adam Bergstein

Right arrow

Contact Forms

Modern websites have the ability to engage users. One of the ways Drupal engages site users is through contact forms, a feature that allows for users to engage through a website generally or personally through user profiles. This chapter covers the basic concepts of creating and configuring contact forms in a Drupal application, including access control and form submissions. Finally, the chapter covers a few popular ways to extend out-of-the-box contact forms.

In this chapter, we’re going to cover the following main topics:

  • Contact forms in Drupal
  • Configuring contact forms
  • Extending contact forms

Contact forms in Drupal

Have you ever gone to a website that has a “Contact us” page where a visitor can fill out a form? That is contact forms in Drupal. They give visitors to a site a means of communicating with those who run it. This could be someone who wants to inquire about hosting a party at a restaurant or leveraging services to remodel a house. It is very common for a website to offer more than just a phone number, especially given the ability to communicate digitally.

Basic information

The contact forms feature comes out of the box with Drupal in the Contact module. Forms are commonly exposed to end users that allow for engagement through the Drupal application.

The Contact module represents one of the more lightweight systems in Drupal. It is composed of an entity type, and contact forms, with bundles for each form. Form submissions represent instances of the entity. Given that it leverages entities, contact forms are fieldable, much like other structured...

Configuring contact forms

Most of the configuration for contact forms happens through the aforementioned form configuration operations due to their association with structured content in Drupal. There are a few more configurations possible.

User profile configuration

It should not be assumed that a Drupal application wants to have engagement with users. While this feature is provided out of the box, it can be turned off by default globally through Drupal’s account settings configuration at admin/config/people/accounts. Each logged-in user can enable or disable a form at their discretion by editing their user profile and changing the Personal Contact Form setting.

Permissions

Before launching the Drupal application, double-check the contact form permissions:

Figure 13.4 – Permissions for contact forms

Figure 13.4 – Permissions for contact forms

Figure 13.4 shows how to map roles to control both who can use or access the forms themselves and who has permission to administer...

Extending contact forms

Like most features in Drupal, contact forms can be extended to address a few common use cases not found out of the box.

Viewing and managing form submissions

Unlike other entity types in Drupal, there is no management interface for form submissions out of the box. The Contact Storage project (drupal.org/project/contact_storage) provides persistent storage and an administrative interface that allows you to view and manage form submissions. This is a useful feature that helps expose form submissions in Drupal rather than relying on email notifications.

Beyond just a page

By default, the experience of using a contact form is like building a page. However, the Contact Block project allows for contact forms to be exposed as blocks. Managing blocks is covered in greater detail in Chapter 15. This allows for a contact form to leverage block visibility settings to be displayed through various contextual options across pages and in specific regions of the...

Summary

This chapter covered Drupal’s contact forms feature, which is useful for both site-specific and user-specific engagement. Contact forms have various out-of-the-box features, such as response messaging, auto-replies, and more. They are also fieldable to allow you to collect responses with specific information. Extending forms to prevent spam, have persistent form submissions, or have greater control over response messages are all possible through contributed projects.

The next chapter pivots into the experience of managing content and media within Drupal. All site builders must understand Drupal through the experience of content authors, and the next chapter introduces the basics built from Drupal’s native structured content.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Drupal 10 Masterclass
Published in: Dec 2023Publisher: PacktISBN-13: 9781837633104
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Adam Bergstein

Adam Bergstein is a product engineering leader and an architect. He has been a long-time Drupal community member, a routine speaker at Drupal community events around the globe, and provided keynotes for several events. He has maintained and contributed to many Drupal projects, including Password Policy, Taxonomy Menu, and more. Adam is the lead of Simplytest, a free service, and a project that offers Drupal community members testing sandboxes. He has also worked for both agencies building Drupal applications and Drupal service providers building Drupal-related products. He has led the Drupal Community Governance Task Force and is serving a term as a community board member of the Drupal Association.
Read more about Adam Bergstein