addElement( 'text', 'firstName', array( 'label' => 'First Name', 'maxlength' => 255, 'required' => true, ) ); $form->addElement( 'text', 'lastName', array( 'label' => 'Last Name', 'maxlength' => 255, 'required' => true, ) ); $form->addElement( 'text', 'email', array( 'label' => 'Email address', 'maxlength' => 255, 'required' => true, 'filters' => array('StringTrim'), ) ); $form->email->addValidator( 'EmailAddress', false, array( 'domain' => false, 'messages' => array( Zend_Validate_EmailAddress::INVALID => 'Email Address is in wrong format', Zend_Validate_EmailAddress::INVALID_FORMAT => 'Email Address is in wrong format' ) ) ); $form->addElement('captcha', 'captcha'); $form->addFormRule(array($this, 'validateForm')); return $this; } public function validateForm($data) { $errors = array(); if (!empty($data['email'])) { $status = $this->dataObj->getSubscriptionStatus($data['email']); if (App_Association_Subscribe_Obj::SUBSCRIPTION_EXISTS === $status) { $errors['email'] = 'This email address is already subscribed.'; } elseif(App_Association_Subscribe_Obj::USER_UNSUBSCRIBED === $status) { $errors['email'] = 'This email address is unsubscribed.'; } } return (empty($errors)) ? true : $errors; } protected function _bindFormButtons($form) { $form->addElement('submit', 'btnSubmit', array( 'label' => 'Subscribe', 'attribs' => array('class' => 'btn'), 'decorators' => array('ViewHelper') ) ); $decorators = array('FormElements'); $decorators[] = array('decorator' => 'HtmlTag', 'options' => array('tag' => 'div')); $decorators[] = 'Fieldset'; $decorators[] = 'DtDdWrapper'; $form->addDisplayGroup(array('btnSubmit', 'btnCancel'), 'submitGroup', array('decorators' => $decorators)); return $this; } protected function _setBackMessage($msg = null) { return true; } protected function _renderForm($form, $template = null, $item = array()) { $this->doc->assign('_appThankYouContact', $this->getShowThankYou()); parent::_renderForm($form, $template, $item); } protected function _addItem($item) { $item['templatePath'] = $this->_getTemplatePath(); $item['viewAlias'] = BASE_URL_LANGUAGE . '/' . Qs_SiteMap::find(null, array('type' => 'Association_'), array('type' => 'default'), 'fullAlias'); $this->doc->addItem($item); return $this; } protected function _postInsert() { $this->setShowThankYou(); return $this; } public function setShowThankYou() { $session = $this->_getSession(); $session->subscribeNewsFormNotification = true; $session->setExpirationHops(1, 'subscribeNewsFormNotification'); return $this; } protected function _getSession() { if (null === $this->_session) { $this->_session = new Qs_Session_Namespace(get_class($this), true); } return $this->_session; } public function getShowThankYou() { $session = $this->_getSession(); return (bool) $session->subscribeNewsFormNotification; } }