QuickForm: improve submission detection

Still not complete
This commit is contained in:
Thomas Gelf 2015-06-24 14:54:14 +02:00
parent 72961586c5
commit fc2352fb1e
17 changed files with 41 additions and 33 deletions

View File

@ -47,7 +47,6 @@ class IcingaCommandArgumentForm extends DirectorObjectForm
$this->translate('Whether this is a mandatory parameter')
);
*/
$this->addElement('submit', $this->translate('Store'));
}
protected function addCustomVariable($varname)

View File

@ -50,7 +50,5 @@ class IcingaCommandForm extends DirectorObjectForm
'template' => $this->translate('Command template'),
))
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -53,7 +53,5 @@ class IcingaEndpointForm extends DirectorObjectForm
'description' => $this->translate('Check this host in this specific Icinga cluster zone'),
'required' => true
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -94,7 +94,5 @@ class IcingaHostForm extends DirectorObjectForm
'label' => $this->translate('Cluster Zone'),
'description' => $this->translate('Check this host in this specific Icinga cluster zone')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -37,7 +37,5 @@ class IcingaHostGroupForm extends DirectorObjectForm
'label' => $this->translate('Display Name'),
'description' => $this->translate('The name which should displayed.')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -20,7 +20,5 @@ class IcingaHostGroupMemberForm extends DirectorObjectForm
'label' => $this->translate('Host'),
'description' => $this->translate('The name of the host')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -11,7 +11,6 @@ class IcingaHostVarForm extends DirectorObjectForm
{
public function setup()
{
$this->addElement('select', 'host_id', array(
'label' => $this->translate('Host'),
'description' => $this->translate('The name of the host'),
@ -32,7 +31,5 @@ class IcingaHostVarForm extends DirectorObjectForm
'label' => $this->translate('Format'),
'description' => $this->translate('value format')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -84,7 +84,5 @@ class IcingaServiceForm extends DirectorObjectForm
'label' => $this->translate('Servicegroups'),
'description' => $this->translate('One or more comma separated servicegroup names')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -37,7 +37,5 @@ class IcingaServiceGroupForm extends DirectorObjectForm
'label' => $this->translate('Display Name'),
'description' => $this->translate('The name which should displayed.')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -20,7 +20,5 @@ class IcingaServiceGroupMemberForm extends DirectorObjectForm
'label' => $this->translate('Service'),
'description' => $this->translate('The name of the service')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -31,7 +31,5 @@ class IcingaServiceVarForm extends DirectorObjectForm
'label' => $this->translate('Format'),
'description' => $this->translate('value format')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -48,7 +48,5 @@ class IcingaTimePeriodForm extends DirectorObjectForm
'description' => $this->translate('Check this host in this specific Icinga cluster zone'),
'required' => true
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -59,7 +59,5 @@ class IcingaUserForm extends DirectorObjectForm
'label' => $this->translate('Usergroups'),
'description' => $this->translate('One or more comma separated usergroup names')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -42,7 +42,5 @@ class IcingaUserGroupForm extends DirectorObjectForm
'label' => $this->translate('Cluster Zone'),
'description' => $this->translate('Check this usergroup in this specific Icinga cluster zone')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -20,7 +20,5 @@ class IcingaUserGroupMemberForm extends DirectorObjectForm
'label' => $this->translate('User'),
'description' => $this->translate('The name of the user')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -37,7 +37,5 @@ class IcingaZoneForm extends DirectorObjectForm
'label' => $this->translate('Parent Zone'),
'description' => $this->translate('Chose an (optional) parent zone')
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -46,6 +46,8 @@ abstract class QuickForm extends Zend_Form
protected $successMessage;
protected $submitLabel;
public function __construct($options = null)
{
parent::__construct($options);
@ -55,6 +57,14 @@ abstract class QuickForm extends Zend_Form
$this->regenerateCsrfToken();
$this->setup();
$this->onSetup();
$this->addSubmitButtonIfSet();
}
protected function addSubmitButtonIfSet()
{
if (false !== ($label = $this->getSubmitLabel())) {
$this->addElement('submit', $label);
}
}
protected function createIdElement()
@ -64,6 +74,21 @@ abstract class QuickForm extends Zend_Form
$this->getElement(self::ID)->setIgnore(true);
}
public function getSubmitLabel()
{
if ($this->submitLabel === null) {
return $this->translate('Submit');
}
return $this->submitLabel;
}
public function setSubmitLabel($label)
{
$this->submitLabel = $label;
return $this;
}
public function regenerateCsrfToken()
{
if (! $element = $this->getElement(self::CSRF)) {
@ -114,7 +139,22 @@ abstract class QuickForm extends Zend_Form
public function hasBeenSubmitted()
{
return $this->hasBeenSent();
if ($this->hasBeenSubmitted === null) {
$req = $this->getRequest();
if ($req->isPost()) {
$post = $req->getPost();
$label = $this->getSubmitLabel();
if ($label === false) {
$this->hasBeenSubmitted = $this->hasBeenSent();
}
$this->hasBeenSubmitted = array_key_exists($label, $post) &&
$post[$label] === $label;
} else {
$this->hasBeenSubmitted === false;
}
}
return $this->hasBeenSubmitted;
}
protected function beforeValidation($data = array())