function BanAdmin::validateForm

Same name in other branches
  1. 9 core/modules/ban/src/Form/BanAdmin.php \Drupal\ban\Form\BanAdmin::validateForm()
  2. 8.9.x core/modules/ban/src/Form/BanAdmin.php \Drupal\ban\Form\BanAdmin::validateForm()
  3. 10 core/modules/ban/src/Form/BanAdmin.php \Drupal\ban\Form\BanAdmin::validateForm()

Overrides FormBase::validateForm

File

core/modules/ban/src/Form/BanAdmin.php, line 109

Class

BanAdmin
Displays banned IP addresses.

Namespace

Drupal\ban\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
    $ip = trim($form_state->getValue('ip'));
    if ($this->ipManager
        ->isBanned($ip)) {
        $form_state->setErrorByName('ip', $this->t('This IP address is already banned.'));
    }
    elseif ($ip == $this->getRequest()
        ->getClientIP()) {
        $form_state->setErrorByName('ip', $this->t('You may not ban your own IP address.'));
    }
    elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) == FALSE) {
        $form_state->setErrorByName('ip', $this->t('Enter a valid IP address.'));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.