Drupal provides a standard, secured method for module developers to add forms to a Drupal website. This method involves building render arrays in PHP and using predefined keys to specify various form element properties. The Form API describes properties for use in form arrays as well as base classes to extend, interfaces to implement, and methods for identifying, building, validating, and submitting the form.

The Configuration API also includes a special class for handling configuration settings forms, the ConfigFormBase class. See the Configuration API for Developers topic for more details about implementing configuration forms in Drupal.

Example tasks

  • Create custom forms in Drupal
  • Alter existing forms
  • Configure Drupal's core Contact module-provided forms (see the External Resources section)

Confidence

While there are many similarities to the Drupal 7 Form API, Drupal's current API is distinct, mostly in its implementation of object-oriented PHP. When browsing resources on the Form API, tutorials based on Drupal 7's Form API will likely need at least some minor adjustments in order to work in a Drupal form today. It's best to use resources written for Drupal 8 and above.

Drupalize.Me resources

Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial
Tutorial

The Form API uses the Render API, so it's a good idea to familiarize yourself with the Render API. It may help you better understand Form API.

Tutorial

Drupal 7

More Guides

We have guides on many Drupal skills and topics.

Explore guides

External resources

Contact module

  • Contact module overview (Drupal.org)
    • Learn how to configure Drupal's built-in personal and site-wide contact forms which are provided by the core Contact module.
  • Drupal Contact Form & using SMTP to Send Email (designkojo.com)
    • Learn how to configure Drupal's built-in contact form and your server's SMTP settings in order to send email to your site's users via the contact form.