Posted By

ischenkodv on 12/24/10


Tagged

form php zend


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

foltrabix
piotrlewandowski


Displaying errors in Zend_Form


 / Published in: PHP
 

  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  

You need to login to post a comment.