/** * Validate the form */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // validate required fields $email = $this->frm->getField('email'); // validate required fields if ($email->isEmail(FL::err('EmailIsInvalid'))) { if (FrontendMailmotorModel::isSubscribed($email->getValue())) { $email->addError(FL::err('AlreadySubscribed')); } } // no errors if ($this->frm->isCorrect()) { try { // subscribe the user to our default group if (!FrontendMailmotorCMHelper::subscribe($email->getValue())) { throw new FrontendException('Could not subscribe'); } // trigger event FrontendModel::triggerEvent('Mailmotor', 'after_subscribe', array('email' => $email->getValue())); // redirect $this->redirect(FrontendNavigation::getURLForBlock('Mailmotor', 'Subscribe') . '?sent=true#subscribeForm'); } catch (\Exception $e) { // make sure RedirectExceptions get thrown if ($e instanceof RedirectException) { throw $e; } // when debugging we need to see the exceptions if ($this->getContainer()->getParameter('kernel.debug')) { throw $e; } // show error $this->tpl->assign('subscribeHasError', true); } } else { $this->tpl->assign('subscribeHasFormError', true); } } }
/** * Validate the form */ private function validateForm() { // is the form submitted if ($this->frm->isSubmitted()) { // get values $email = $this->frm->getField('email'); // validate required fields if ($email->isEmail(FL::err('EmailIsInvalid'))) { // email does not exist if (!FrontendMailmotorModel::exists($email->getValue())) { $email->addError(FL::err('EmailNotInDatabase')); } // user is already unsubscribed if (!FrontendMailmotorModel::isSubscribed($email->getValue(), $this->group)) { $email->addError(FL::err('AlreadyUnsubscribed')); } } // no errors and email address does not exist if ($this->frm->isCorrect()) { try { // unsubscribe the user from our default group if (!FrontendMailmotorCMHelper::unsubscribe($email->getValue(), $this->group)) { throw new FrontendException('Could not unsubscribe'); } // trigger event FrontendModel::triggerEvent('Mailmotor', 'after_unsubscribe', array('email' => $email->getValue())); // redirect $this->redirect(FrontendNavigation::getURLForBlock('Mailmotor', 'Unsubscribe') . '?sent=true#unsubscribeForm'); } catch (\Exception $e) { // when debugging we need to see the exceptions if ($this->getContainer()->getParameter('kernel.debug')) { throw $e; } // show error $this->tpl->assign('unsubscribeHasError', true); } } else { $this->tpl->assign('unsubscribeHasFormError', true); } } }