QuickForm: postpone setup() call

This commit is contained in:
Thomas Gelf 2015-07-28 11:37:08 +02:00
parent 570a0ac00a
commit 38501e8e96
1 changed files with 19 additions and 3 deletions

View File

@ -49,6 +49,11 @@ abstract class QuickForm extends Zend_Form
protected $submitLabel;
/**
* Whether form elements have already been created
*/
protected $didSetup = false;
/**
* The Icinga module this form belongs to. Usually only set if the
* form is initialized through the FormLoader
@ -66,9 +71,6 @@ abstract class QuickForm extends Zend_Form
$this->setAction(Url::fromRequest());
$this->createIdElement();
$this->regenerateCsrfToken();
$this->setup();
$this->onSetup();
$this->addSubmitButtonIfSet();
}
protected function addSubmitButtonIfSet()
@ -197,12 +199,26 @@ abstract class QuickForm extends Zend_Form
{
}
public function prepareElements()
{
if (! $this->didSetup) {
$this->setup();
$this->onSetup();
$this->addSubmitButtonIfSet();
$this->didSetup = true;
}
return $this;
}
public function handleRequest(Request $request = null)
{
if ($request !== null) {
$this->request = $request;
}
$this->prepareElements();
if ($this->hasBeenSent()) {
$post = $this->getRequest()->getPost();
if ($this->hasBeenSubmitted()) {