Zend_Form - No error messages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

Zend_Form - No error messages

Post by Cirdan »

I can't seem to figure out why my code won't display the form errors when the user entered something incorrectly? The elements should have the error decorator by default:

Code: Select all

class AuthController extends Zend_Controller_Action
{   
    public function indexAction()
    {
        $this->view->form = $this->getForm();
        $this->render('form');
    }
    
    public function loginAction()
    {
        if(!$this->getRequest()->isPost())
        {
            return $this->_forward('index');
        }
        
        $form = $this->getForm();
        
        if(!$form->isValid($_POST))
        {
            $this->view->errors = $form->getMessages();
            $this->view->form = $this->getForm();
            return $this->render('form');
        }
        
        $values = $form->getValues();
        
    }
    
    public function getForm()
    {
        $config = new Zend_Config_Ini(APPLICATION_PATH . '/config/config.ini', 'application');
        
        $form = new Zend_Form();
        
        $form->setAction('/auth/login')
             ->setMethod('post');
            
        $username = $form->createElement('text', 'username', array('label' => 'Username'));
        $username->setRequired(true)
                 ->addValidator('regex', false, array('/^[a-zA-Z0-9\s\-_]+/'))
                 ->addValidator('stringLength', false, 
                        array($config->auth->min_username_length, 
                              $config->auth->max_username_length));
                        
        $password = $form->createElement('password', 'password', array('label' => 'Password'));
        $password->setRequired(true)
                 ->addValidator('stringLength', false,
                        array($config->auth->min_password_length, 
                              $config->auth->max_password_length));
        
        $form->addElement($username)
             ->addElement($password)
             ->addElement('submit', 'login', array('label' => 'Login'));
            
        return $form;
        
    }
}
The view is simple

Code: Select all

<h3>Please login</h3>
<?=$this->form?>
Post Reply