// Get the value of a form element with ID 'my_element' $value = $form_state->getValue('my_element');
// Get the submitted value of a form element with ID 'my_element' $value = $form_state->getValues()['my_element'];
// Get the error messages for a form element with ID 'my_element' $errors = $form_state->getErrors('my_element');These code examples are part of the Drupal core library and can be found in the FormStateInterface class in the Form API package.