ZF-9584: Zend_Form getValues() incorrect handling when !$subform->isArray()
Description
Zend_Form getValues() does not handle Form Structure correctly, when calling getValues(), having a Form or a SubForm set isArray(false);
foreach ($this->getSubForms() as $key => $subForm) {
$fValues = $this->_attachToArray($subForm->getValues(true), $subForm->getElementsBelongTo());
// the result
if (!$subForm->isArray()) {
$fValues === array('' => array('foo' => ...
}
// because
if (!$subForm->isArray()) {
null === $subForm->getElementsBelongTo()
}
}
I added the solution from the previous two patches [ZF-9586] and [ZF-9467] (interferencing Name and elementsBelongTo with array_merge) here as well.
This patch fixes the issue, Unit Test included
Index: tests/Zend/Form/FormTest.php
===================================================================
--- tests/Zend/Form/FormTest.php (Revision 21726)
+++ tests/Zend/Form/FormTest.php (Arbeitskopie)
@@ -1579,7 +1621,14 @@
$this->assertSame($this->form->getValidValues($data['invalid']), $data['partial']);
}
+ public function testGetValuesWithElementsBelongTo()
+ {
+ $data = $this->_setup9350();
+ $this->form->populate($data['valid']);
+ $this->assertSame($this->form->getValues(), $data['valid']);
+ }
+
// Display groups
public function testCanAddAndRetrieveSingleDisplayGroups()
Index: library/Zend/Form.php
===================================================================
--- library/Zend/Form.php (Revision 21726)
+++ library/Zend/Form.php (Arbeitskopie)
@@ -1307,8 +1307,14 @@
}
}
foreach ($this->getSubForms() as $key => $subForm) {
- $fValues = $this->_attachToArray($subForm->getValues(true), $subForm->getElementsBelongTo());
- $values = array_merge($values, $fValues);
+ $merge = array();
+ if (!$subForm->isArray()) {
+ $merge[$key] = $subForm->getValues();
+ } else {
+ $merge = $this->_attachToArray($subForm->getValues(true),
+ $subForm->getElementsBelongTo());
+ }
+ $values = array_merge_recursive($values, $merge);
}
if (!$suppressArrayNotation && $this->isArray()) {
Comments
Posted by Matthew Weier O'Phinney (matthew) on 2010-04-16T12:49:12.000+0000
Patch applied to trunk and 1.10 release branch.