[Drupal 7] Form API

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

This guide covers Drupal 7 (Legacy). For the most recent standards and best practices, see the modern guide version: Form API

Collecting and processing user-submitted data is important.

Placing a form on a webpage and getting user responses are easy - getting them securely is harder. Drupal provides a standard, easy to use, easy to extend and secure way of adding forms to your Drupal website: Form API (FAPI).

This guide describes what you can do using the Form API.

Make sure you use your form values safely.

See also Form API Reference.

Creating a builder function to generate a form

Form workflow usually follows these stages:

Form API Internal Workflow Illustration

This workflow actually includes some of the nodeapi hooks as well as FAPI workflow to help illustrate the places where form elements can be

Forms API - Modify Form widgets with hook_field_widget_form_alter()

Widgets are the parts that make up forms, like textarea widgets, file upload widgets etc.

Forms API - Modify Forms with hook_form_alter()

Drupal 7 forms that modules create can be changed by other modules and even themes with the help of Drupal FAPI hooks system. See Drupal 7

#tree and #parents

Explain the use of #tree and #parents properties in a form array.

Guide maintainers

banoodle's picture