Skip to main content

Form API

Displaying 1 - 8 of 8

Form Element 'table' with TableDrag and TableSelect

Building and rendering a table required writing a custom/dedicated theme function for most tables in Drupal 7.

Drupal 8 introduces a new element '#type' => 'table', which comes with built-in, optional support for TableDrag and TableSelect, and which requires no more custom plumbing for most use-cases.

Note: The following conversion example shows both TableDrag and TableSelect in a single table for brevity, but they are usually not combined in a single table.

How to change an existing Drupal form

Changing an existing form is one of the first things that new Drupal developers will learn how to do. 

It is a natural extension from site building, where you might need to change one thing on a form created by a core or contributed module. 

One of the benefits of using the Form API to construct forms is that any module can alter any other module's form. 

In this tutorial, you are going to learn how to alter a Drupal form.

Building Forms Programmatically

Drupal provides a Form API in order to achieve consistency in its form processing and presentation while simplifying code and reducing the amount of HTML that a module must explicitly generate.

FormBuilder handles the low-level processing of forms such as rendering the necessary HTML, initial processing of incoming $_POST data, and delegating to your implementation of FormInterface to validate and process submitted data.

Advance Examples Which actually needed

This article is based on the O'Reilly article which is relevant to Drupal7 and some of it for Drupal8, but drupal did a lot of modifications since then, and I believe it's a good place to start with, but still should be modified to Drupal9 and on. from time to time I will fix this article and update it according to the last drupal version, you are all invited to send me remarks and suggestions.

These examples, I believe are most needed for the more advanced Drupal backend developer.

My development strategy recommendations are: