Forms (user input)

In Drupal 8, all the parts of the form are contained within a single class. The buildForm method is where you define what your form will look like. This is done using the Form API which is very similar to what was used in Drupal 7. The validateForm method allows you to validate the user submitted data and give feedback to the user and the submitForm method allows you to act on the data submitted.

Defining forms as structured arrays, instead of as straight HTML, has many advantages including:

  • Consistent HTML output for all forms.

  • Forms provided by one module can be easily altered by another without complex search and replace logic.

  • Complex form elements like file uploads and voting widgets can be encapsulated in reusable bundles that include both display and processing logic.

Excerpt from Official Drupal Docs: Introduction to Form API

Tripal uses the Drupal Form API without any modification and your form classes will be saved, one per file, in the src/forms directory of your extension module.

Additional Resources: