You are here

public function SecuresiteSettingsForm::validateForm in Secure Site 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/SecuresiteSettingsForm.php, line 135
Contains \Drupal\securesite\Form\SecuresiteSettingsForm.

Class

SecuresiteSettingsForm

Namespace

Drupal\securesite\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  foreach ($form_state['values']['securesite_type'] as $type => $value) {
    if (empty($value)) {
      unset($form_state['values']['securesite_type'][$type]);
    }
  }
  sort($form_state['values']['securesite_type']);
  $name = $form_state['values']['securesite_guest_name'];
  if ($name && db_query_range("SELECT name FROM {users} WHERE name = :name", 0, 1, array(
    ':name' => $name,
  ))
    ->fetchField() == $name) {
    $form_state
      ->setErrorByName('securesite_guest_name', $form_state, t('The name %name belongs to a registered user.', array(
      '%name' => $name,
    )));
  }
}