Is there a function (in Drupal 8) to build an array containing the submitted values in
$form state? If I use
$form_state->getValues(), I get more values than the ones I need.
If you are getting values like form_id, form_token, or form_build_id, which you don't want, then you need to use the following code.
$values = $form_state->cleanValues()->getValues();
The documentation for
This function can be used when a module wants to store all submitted form values, for example, by serializing them into a single database column. In such cases, all internal Form API values and all form button elements should not be contained, and this function allows their removal before the module proceeds to storage. Next to button elements, the following internal values are removed by default.
$this, so it can be used in chained calls, as in the code I showed.