Processing submitted form data
A form's purpose is to collect data and do something with the data that was submitted. All forms need to implement the \Drupal\Core\Form\FormInterface
interface. The interface defines a submit method. Once the Form API has invoked the class's validation method, the submit method can be run.
This recipe will be based on the custom module and form created in the Creating a form recipe of this chapter. We will convert the form to \Drupal\Core\FormConfigBaseForm
, allowing us to save our configuration and reuse code provided by Drupal core.
Getting ready
In this recipe, we will use the module and custom form created in the first Creating a form recipe.
How to do it...
- In your module's directory, create a
config
directory, and then create a directory inside it namedinstall
.
- Create a file named
drupalform.schema.yml
. This file will tell Drupal about the configuration item that we want to save.
- Add the following configuration schema definition to
drupalform.schema.yml
:
...