Zend_Form - No error messages
Posted: Wed Jan 21, 2009 11:30 am
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:
The view is simple
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;
}
}Code: Select all
<h3>Please login</h3>
<?=$this->form?>