_namespace = new Zend_Session_Namespace(); return $this; } protected function _bindFormFields($form) { $form->addElement('text', 'name', array('label' => 'Your Name', 'required' => true)); $form->addElement('text', 'emailOrPhone', array('label' => 'Email or Phone Number', 'required' => true)); $form->addElement('textarea', 'comments', array('label' => 'Message', 'required' => true, 'rows' => 10)); // //$form->addElement('captcha', 'captcha'); $form->addElement( 'text', 'captcha', array('label' => '', 'required' => true, 'description' => '(This is to make sure you are a human user)') ); $form->captcha->getDecorator('Description')->setOption('placement', 'PREPEND'); $form->captcha->addFilter('StringTrim'); $form->captcha->addValidator('Identical', true); $form->captcha->getValidator('Identical')->setToken((string) $this->_namespace->equationResult) ->setMessage('Your result does not match the given equation', Zend_Validate_Identical::NOT_SAME); return $this; } protected function _bindFormButtons($form) { $form->addElement('submit', 'btnSubmit', array( 'label' => 'Submit Message', '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 _getMailData(array $data) { $mailData = array( 'name' => htmlspecialchars($data['name']), 'emailOrPhone' => htmlspecialchars($data['emailOrPhone']), 'comments' => nl2br(htmlspecialchars($data['comments'])), 'link' => BASE_URL . '/' . Qs_SiteMap::findFirst(null, array('type' => 'Form_Contact_Admin'), null, 'fullAlias') . '?action=view&id=' . $data['id'], ); return $mailData; } protected function _renderMainForm($form) { $equation = $this->_generateEquation(); $form->captcha->setLabel("What is {$equation}?"); $this->_renderForm($form, 'form.tpl'); return $this; } protected function _generateEquation() { $x = rand(1, 9); $y = rand(1, 9); $this->_namespace->equationResult = $x + $y; return "{$x} + {$y}"; } }