public BanAdmin::validateForm(array &$form, FormStateInterface $form_state)
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
- core/modules/ban/src/Form/BanAdmin.php, line 102
Class
- BanAdmin
- Displays banned IP addresses.
Namespace
Drupal\ban\Form
Code
1 2 3 4 5 6 7 8 9 10 11 12 | 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.' )); } } |
Please login to continue.