Module Development

Save Form Data Submitted by a User for Drupal 8, 9, 10, and 11

The submitForm() method in a form controller is responsible for handling submitted data. This method can save data to the database (including updating configuration), trigger workflows based on user input, and redirect users after form processing. By the time data reaches submitForm(), it has been validated and is ready for use.

In this tutorial, we'll:

  • Add a submitForm() method to the form controller.
  • Save user-provided settings to the database.
  • Confirm successful data submission to the user.

By the end of this tutorial, you'll understand how to implement custom submit handling logic in a form.

Drupal Module Developer Guide