From 2f179b81e33e0846583c89aca39a5bbcd9fdc281 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 23 Feb 2016 11:04:09 -0500 Subject: [PATCH] Make subscribe form work --- src/Form/SubscribeForm.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Form/SubscribeForm.php b/src/Form/SubscribeForm.php index fa488dd..9adf37f 100644 --- a/src/Form/SubscribeForm.php +++ b/src/Form/SubscribeForm.php @@ -58,13 +58,23 @@ public function validateForm(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - foreach($form_state['values']['lists'] as $list_id) { + $values = $form_state->getValues(); + foreach($values['lists'] as $list_id) { if(!$list_id) { continue; } - $email = check_plain($form_state['values']['email']); + $email_okay = \Drupal::service('email.validator')->isValid($values['email']); + if ($email_okay) { + $email = $values['email']; + } + else { + form_set_error('', t('Please submit a valid email address.')); + $form_state['redirect'] = FALSE; + return FALSE; + } + $cm = CampaignMonitor::getConnector(); // Update subscriber information or add new subscriber to the list.