You are here

public function AddUserToChannelForm::validateForm in Node.js integration 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/AddUserToChannelForm.php, line 46

Class

AddUserToChannelForm

Namespace

Drupal\nodejs\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  if (!preg_match('/^\\d+$/', $form_state
    ->getValue('nodejs_uid'))) {
    $form_state
      ->setErrorByName('nodejs_uid', $this
      ->t('Invalid uid - please enter a numeric uid.'));
  }
  if (!preg_match('/^([a-z0-9_]+)$/i', $form_state
    ->getValue('nodejs_channel'))) {
    $form_state
      ->setErrorByName('nodejs_channel', $this
      ->t('Invalid channel name - only numbers, letters and underscores are allowed.'));
  }
}