public function ContactForm::validateForm in Email Contact 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/ ContactForm.php, line 86
Class
Namespace
Drupal\email_contact\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
if (!\Drupal::service('email.validator')
->isValid($form_state
->getValue('mail'))) {
$form_state
->setErrorByName('mail', $this
->t('You must enter a valid e-mail address.'));
}
if (preg_match("/\r|\n/", $form_state
->getValue('subject'))) {
$form_state
->setErrorByName('subject', $this
->t('The subject cannot contain linebreaks.'));
$msg = 'Email injection exploit attempted in email form subject: @subject';
$this
->logger('email_contact')
->notice($msg, [
'@subject' => $form_state['values']['subject'],
]);
}
}