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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.