Last updated April 4, 2018

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 8.

Example tasks

  • Create custom forms in Drupal 8
  • Alter existing forms


While there are many similarities to the Drupal 7 Form API, the Drupal 8 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 8 form.

Drupalize.Me resources

The Form API uses the Render API, so it's a good idea to familiarize yourself with the Render API before diving into building forms programmatically in Drupal.

Drupal 8

Drupal 7

More Guides

We have guides on many Drupal skills and topics.

Explore guides

External resources

  • Generating a Form with Drupal Console (
    • Learn how to use Drupal Console to generate boilerplate code for a form in Drupal 8
  • Introduction to the Form API (
    • Learn about the new features of the Form API in Drupal 8; get an overview of the process of form building; learn about the classes and interfaces for use with forms; learn how to identify your form, build, validate, and submit it; and learn to alter an existing form with a hook.
  • Form generation (
    • The Drupal API page describes how to generate and manipulate forms and process form submissions.
  • Form and render elements (
    • This list contains all of the FormElement render elements that you can use in a form.
  • Change record: HTML5 support for form elements (
    • This is a list of HTML5 form elements that were introduced in Drupal 8, along with code usage examples.
  • Examples for Developers: Form API Example (
    • The Examples for Developers project provides code examples of various APIs in Drupal. You can download the project and browse the examples using your code editor or IDE of your choice.
  • Drupal 8 API: forms (
    • This article describes in detail how to implement the classes and interfaces related to forms in Drupal 8.
  • Implementing #autocomplete in Drupal 8 with Custom Callbacks (
    • How to implement autocomplete functionality in a form element, including utilizing a custom route and controller.
  • Theming form elements in Drupal 8 (
    • Learn about form-specific template files, preprocess functions, and how to customize the rendering of form elements.