function ContactFormEditForm::validateForm
Same name in other branches
- 9 core/modules/contact/src/ContactFormEditForm.php \Drupal\contact\ContactFormEditForm::validateForm()
- 8.9.x core/modules/contact/src/ContactFormEditForm.php \Drupal\contact\ContactFormEditForm::validateForm()
- 11.x core/modules/contact/src/ContactFormEditForm.php \Drupal\contact\ContactFormEditForm::validateForm()
Overrides FormBase::validateForm
File
-
core/
modules/ contact/ src/ ContactFormEditForm.php, line 137
Class
- ContactFormEditForm
- Base form for contact form edit forms.
Namespace
Drupal\contactCode
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.', [
'%recipient' => $recipient,
]));
}
}
$form_state->setValue('recipients', $recipients);
$redirect_url = $form_state->getValue('redirect');
if ($redirect_url && $this->pathValidator
->isValid($redirect_url)) {
if (mb_substr($redirect_url, 0, 1) !== '/') {
$form_state->setErrorByName('redirect', $this->t('The path should start with /.'));
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.