Displaying errors in Zend_Form


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public function loginAction()
  2. {
  3. $form = new Application_Form_Login();
  4. if ($this->getRequest()->isPost()){
  5. if ($form->isValid($this->getRequest()->getPost())){
  6. $username = $form->getValue('username');
  7. $userpass = $form->getValue('userpass');
  8. $adapter = new Application_Model_AuthAdapter($username, $userpass);
  9. $result = $this->_auth->authenticate($adapter);
  10. if ($result->isValid()){
  11. // Success.
  12. // Redirect...
  13. } else {
  14. $form->setErrors(array('Invalid user/pass'));
  15. $form->addDecorator('Errors', array('placement' => 'prepend'));
  16. }
  17. } else {
  18. $form->setErrors(array('Please note the errors below'));
  19. $form->addDecorator('Errors', array('placement' => 'prepend'));
  20. }
  21. }
  22. $this->view->form = $form;
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.