Skip to content

Commit

Permalink
Form: Don't prevent disabled elements from getting overwritten..
Browse files Browse the repository at this point in the history
..if someone just utilizes populate() programatically.

refs #2509
  • Loading branch information
nilmerg committed Jul 13, 2017
1 parent ed5ba14 commit eb34300
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions library/Icinga/Web/Form.php
Expand Up @@ -1102,21 +1102,22 @@ public function populate(array $defaults)
*
* @param Zend_Form $form
* @param array $defaults
* @param bool $ignoreDisabled
*/
protected function preserveDefaults(Zend_Form $form, array & $defaults)
protected function preserveDefaults(Zend_Form $form, array & $defaults, $ignoreDisabled = true)
{
foreach ($form->getElements() as $name => $element) {
if ((array_key_exists($name, $defaults)
&& array_key_exists($name . static::DEFAULT_SUFFIX, $defaults)
&& $defaults[$name] === $defaults[$name . static::DEFAULT_SUFFIX])
|| $element->getAttrib('disabled')
|| (! $ignoreDisabled && $element->getAttrib('disabled'))
) {
unset($defaults[$name]);
}
}

foreach ($form->getSubForms() as $_ => $subForm) {
$this->preserveDefaults($subForm, $defaults);
$this->preserveDefaults($subForm, $defaults, $ignoreDisabled);
}
}

Expand All @@ -1143,6 +1144,11 @@ public function handleRequest(Request $request = null)
if (($frameUpload = (bool) $request->getUrl()->shift('_frameUpload', false))) {
$this->getView()->layout()->setLayout('wrapped');
}

// To prevent a BC, this is here. The proper fix is to extend populate()
// and pass $ignoreDisabled through to preserveDefaults()
$this->create($formData)->preserveDefaults($this, $formData, false);

$this->populate($formData); // Necessary to get isSubmitted() to work
if (! $this->getSubmitLabel() || $this->isSubmitted()) {
if ($this->isValid($formData)
Expand Down

0 comments on commit eb34300

Please sign in to comment.