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', 'hidden',
'backend', 'backend',
array( array(
'required' => true, 'disabled' => true,
'value' => 'autologin' 'value' => 'autologin'
) )
); );

View File

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

View File

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

View File

@ -665,6 +665,14 @@ class Form extends Zend_Form
public function isValidPartial(array $formData) public function isValidPartial(array $formData)
{ {
$this->create($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); return parent::isValidPartial($formData);
} }
@ -678,6 +686,14 @@ class Form extends Zend_Form
public function isValid($formData) public function isValid($formData)
{ {
$this->create($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); return parent::isValid($formData);
} }