You are here

public function AdvbanSearchForm::validateForm in Advanced ban 8

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormBase::validateForm

File

src/Form/AdvbanSearchForm.php, line 149

Class

AdvbanSearchForm
Search banned IP addresses.

Namespace

Drupal\advban\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $ip = trim($form_state
    ->getValue('ip'));
  if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) == FALSE) {
    $form_state
      ->setErrorByName('ip', $this
      ->t('Enter a valid IP address.'));
  }
}