Command masks: Fix lazy initialization of forms

refs #4355
This commit is contained in:
Marius Hein 2013-07-18 10:32:53 +02:00
parent c6ebe85782
commit e9c9c9de87
3 changed files with 37 additions and 8 deletions

View File

@ -71,6 +71,7 @@ class AuthenticationController extends ActionController
if ($this->getRequest()->isPost() && $this->view->form->isValid($this->getRequest())) {
$credentials->setUsername($this->view->form->getValue('username'));
$credentials->setPassword($this->view->form->getValue('password'));

View File

@ -45,6 +45,7 @@ class LoginForm extends Form
'required' => true
)
);
$this->addElement(
'password',
'password',
@ -53,6 +54,7 @@ class LoginForm extends Form
'required' => true
)
);
$this->addElement(
'submit',
'submit',
@ -61,6 +63,7 @@ class LoginForm extends Form
'class' => 'pull-right'
)
);
$this->disableCsrfToken();
}
}

View File

@ -61,6 +61,12 @@ abstract class Form extends \Zend_Form
*/
private $tokenTimeout = 300;
/**
* Flag to indicate that form is already build
* @var bool
*/
private $created = false;
/**
* @see Zend_Form::init
*/
@ -71,16 +77,15 @@ abstract class Form extends \Zend_Form
}
}
/**
* Render the form to html
* @param Zend_View_Interface $view
* @return string
*/
public function render(Zend_View_Interface $view = null)
{
if ($this->_isRendered === false) {
$this->create();
// Empty action if not safe
if (!$this->getAction() && $this->getRequest()) {
$this->setAction($this->getRequest()->getRequestUri());
}
}
// Elements must be there to render the form
$this->buildForm();
return parent::render($view);
}
@ -107,6 +112,23 @@ abstract class Form extends \Zend_Form
return $this->request;
}
/**
* Triggers form creation
*/
public function buildForm()
{
if ($this->created === false) {
$this->create();
// Empty action if not safe
if (!$this->getAction() && $this->getRequest()) {
$this->setAction($this->getRequest()->getRequestUri());
}
$this->created = true;
}
}
/**
* Test if data from array or request is valid
*
@ -119,6 +141,9 @@ abstract class Form extends \Zend_Form
{
$check = null;
// Elements must be there to validate
$this->buildForm();
if ($data === null) {
$check = $this->getRequest()->getParams();
} elseif ($data instanceof \Zend_Controller_Request_Abstract) {