function my_form_submit($form, FormStateInterface $form_state) { $name = $form_state->getValue('name'); if (!$form_state->isValueEmpty('name')) { drupal_set_message(t('Thank you @name!', array('@name' => $name))); } }
function my_form_validate($form, FormStateInterface $form_state) { if ($form_state->isValueEmpty('email')) { $form_state->setErrorByName('email', t('Email is required.')); } }This example shows how FormStateInterface can be used for form validation. The isValueEmpty function is used to check if the 'email' field is empty. If it is, an error message is displayed. The drupal.core.form package is part of the Drupal core, which is the set of modules and code that make up the basic functionality of Drupal.