use Drupal\Core\Form\FormStateInterface; function mymodule_form_submit($form, FormStateInterface $form_state) { // Get the submitted values from the form state $name = $form_state->getValue('name'); $email = $form_state->getValue('email'); // Do something with the data // ... }
use Drupal\Core\Form\FormStateInterface; function mymodule_form_submit($form, FormStateInterface $form_state) { // Check if the submitted value is valid if (!$value_is_valid) { // Set an error message for the form field $form_state->setErrorByName('fieldname', t('The value is not valid.')); } }Package/library: Drupal Core.