Fix that hidden elements are getting ovewritten when validating a form

This works by "disabling" hidden elements which causes the browser not
to submit them. Due to a bug in Zend we need to manually ensure that
Form::isValid does not overwrite the value of disabled elements with null.

fixes #7717
This commit is contained in:
Johannes Meyer 2014-11-18 15:06:36 +01:00
parent 760bf1a020
commit 1cbdd2b51c
4 changed files with 19 additions and 3 deletions

View File

@ -66,7 +66,7 @@ class AutologinBackendForm extends Form
'hidden',
'backend',
array(
'required' => true,
'disabled' => true,
'value' => 'autologin'
)
);

View File

@ -75,7 +75,7 @@ class DbBackendForm extends Form
'hidden',
'backend',
array(
'required' => true,
'disabled' => true,
'value' => 'db'
)
);

View File

@ -96,7 +96,7 @@ class LdapBackendForm extends Form
'hidden',
'backend',
array(
'required' => true,
'disabled' => true,
'value' => 'ldap'
)
);

View File

@ -665,6 +665,14 @@ class Form extends Zend_Form
public function isValidPartial(array $formData)
{
$this->create($formData);
// Ensure that disabled elements are not overwritten (http://www.zendframework.com/issues/browse/ZF-6909)
foreach ($this->getElements() as $name => $element) {
if ($element->getAttrib('disabled')) {
$formData[$name] = $element->getValue();
}
}
return parent::isValidPartial($formData);
}
@ -678,6 +686,14 @@ class Form extends Zend_Form
public function isValid($formData)
{
$this->create($formData);
// Ensure that disabled elements are not overwritten (http://www.zendframework.com/issues/browse/ZF-6909)
foreach ($this->getElements() as $name => $element) {
if ($element->getAttrib('disabled')) {
$formData[$name] = $element->getValue();
}
}
return parent::isValid($formData);
}