You are here

public function EntityAutocomplete::validateForm in Examples for Developers 3.x

Same name and namespace in other branches
  1. 8 ajax_example/src/Form/EntityAutocomplete.php \Drupal\ajax_example\Form\EntityAutocomplete::validateForm()

Here we validate and signal an error if there are no users selected.

Overrides FormInterface::validateForm

File

modules/ajax_example/src/Form/EntityAutocomplete.php, line 105

Class

EntityAutocomplete
A simple autocomplete form which looks up usernames.

Namespace

Drupal\ajax_example\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $state_users = $form_state
    ->getValue('users');
  if (empty($state_users)) {
    $form_state
      ->setErrorByName('users', 'There were no users selected.');
  }
}