[icinga-checkins] icinga.org: icingaweb2/master: Fix that hidden elements are getting ovewritten when validating a form

git at icinga.org git at icinga.org
Tue Nov 18 15:06:51 CET 2014


Module: icingaweb2
Branch: master
Commit: 1cbdd2b51c566eada82efdb5dd5d4e2a569dbf95
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=1cbdd2b51c566eada82efdb5dd5d4e2a569dbf95

Author: Johannes Meyer <johannes.meyer at netways.de>
Date:   Tue Nov 18 15:06:36 2014 +0100

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

---

 .../Config/Authentication/AutologinBackendForm.php     |    2 +-
 .../forms/Config/Authentication/DbBackendForm.php      |    2 +-
 .../forms/Config/Authentication/LdapBackendForm.php    |    2 +-
 library/Icinga/Web/Form.php                            |   16 ++++++++++++++++
 4 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/application/forms/Config/Authentication/AutologinBackendForm.php b/application/forms/Config/Authentication/AutologinBackendForm.php
index 1725ea3..a21d2c0 100644
--- a/application/forms/Config/Authentication/AutologinBackendForm.php
+++ b/application/forms/Config/Authentication/AutologinBackendForm.php
@@ -66,7 +66,7 @@ class AutologinBackendForm extends Form
             'hidden',
             'backend',
             array(
-                'required'  => true,
+                'disabled'  => true,
                 'value'     => 'autologin'
             )
         );
diff --git a/application/forms/Config/Authentication/DbBackendForm.php b/application/forms/Config/Authentication/DbBackendForm.php
index 31e6b24..572a09c 100644
--- a/application/forms/Config/Authentication/DbBackendForm.php
+++ b/application/forms/Config/Authentication/DbBackendForm.php
@@ -75,7 +75,7 @@ class DbBackendForm extends Form
             'hidden',
             'backend',
             array(
-                'required'  => true,
+                'disabled'  => true,
                 'value'     => 'db'
             )
         );
diff --git a/application/forms/Config/Authentication/LdapBackendForm.php b/application/forms/Config/Authentication/LdapBackendForm.php
index 3be140f..9b48c3d 100644
--- a/application/forms/Config/Authentication/LdapBackendForm.php
+++ b/application/forms/Config/Authentication/LdapBackendForm.php
@@ -96,7 +96,7 @@ class LdapBackendForm extends Form
             'hidden',
             'backend',
             array(
-                'required'  => true,
+                'disabled'  => true,
                 'value'     => 'ldap'
             )
         );
diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php
index 75357e2..8d75a9d 100644
--- a/library/Icinga/Web/Form.php
+++ b/library/Icinga/Web/Form.php
@@ -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);
     }
 



More information about the icinga-checkins mailing list