ContactFormEditForm::validateForm

public ContactFormEditForm::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/contact/src/ContactFormEditForm.php, line 136

Class

ContactFormEditForm
Base form for contact form edit forms.

Namespace

Drupal\contact

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  parent::validateForm($form, $form_state);

  // Validate and each email recipient.
  $recipients = explode(',', $form_state->getValue('recipients'));

  foreach ($recipients as &$recipient) {
    $recipient = trim($recipient);
    if (!$this->emailValidator->isValid($recipient)) {
      $form_state->setErrorByName('recipients', $this->t('%recipient is an invalid email address.', array('%recipient' => $recipient)));
    }
  }
  $form_state->setValue('recipients', $recipients);
  $redirect_url = $form_state->getValue('redirect');
  if ($redirect_url && $this->pathValidator->isValid($redirect_url)) {
    if (Unicode::substr($redirect_url, 0, 1) !== '/') {
      $form_state->setErrorByName('redirect', $this->t('The path should start with /.'));
    }
  }
}
doc_Drupal
2016-10-29 08:56:26
Comments
Leave a Comment

Please login to continue.