/** * The default action - register page */ public function indexAction() { $form = new Users_Form_Auth_Register(); if ($this->_request->isPost()) { if ($form->isValid($this->_getAllParams())) { if ($user = $this->_manager->register($form->getValues())) { // confirm email sends to user Mail_Model_Mail::register($user); $message = 'Now you\'re registered! Please ' . 'check your email and confirm your registration'; $this->_flashMessenger->addMessage($message); $this->_helper->redirector(false, false, false); } else { $message = 'Something goes wrong. ' . 'Please fill the registration form again'; } } else { $message = 'Registration error. Please check the form fields'; // show errors $errors = $form->getErrors(); foreach ($errors as $fn => $error) { if (empty($error)) { continue; } $el = $form->getElement($fn); $dec = $el->getDecorator('HtmlTag'); $cls = $dec->getOption('class'); $dec->setOption('class', $cls . ' error'); } } $this->view->messages = $message; } $this->view->form = $form; }
/** * @see Zend_Form::isValid() * @param $data * @return bool */ public function isValid($data) { if ($currentPassword = $this->getElement('currentPassword')) { if (!$this->_row->isEmail($data['email'])) { $currentPassword->setRequired(true); } elseif (!empty($data['password'])) { $currentPassword->setRequired(true); } } return parent::isValid($data); }