diff --git a/library/Zend/Form/Form.php b/library/Zend/Form/Form.php index 3cff8ebf013..43253a9f515 100644 --- a/library/Zend/Form/Form.php +++ b/library/Zend/Form/Form.php @@ -287,7 +287,14 @@ public function bindValues(array $values = array()) } $data = $this->prepareBindData($data, $this->data); - $this->object = parent::bindValues($data); + + // If there is a base fieldset, only hydrate beginning from the base fieldset + if ($this->baseFieldset !== null) { + $data = $data[$this->baseFieldset->getName()]; + $this->object = $this->baseFieldset->bindValues($data); + } else { + $this->object = parent::bindValues($data); + } } /** diff --git a/tests/ZendTest/Form/FormTest.php b/tests/ZendTest/Form/FormTest.php index 0067fe8819f..b31b663feed 100644 --- a/tests/ZendTest/Form/FormTest.php +++ b/tests/ZendTest/Form/FormTest.php @@ -19,6 +19,7 @@ use Zend\InputFilter\InputFilter; use Zend\InputFilter\Factory as InputFilterFactory; use Zend\Stdlib\Hydrator; +use ZendTest\Form\TestAsset\Entity; class FormTest extends TestCase { @@ -1161,4 +1162,41 @@ public function testResetPasswordValueIfFormIsNotValid() $this->assertEquals('', $this->form->get('password')->getValue()); } + + public function testCorrectlyHydrateBaseFieldsetWhenHydratorThatDoesNotIgnoreInvalidDataIsUsed() + { + $fieldset = new Fieldset('example'); + $fieldset->add(array( + 'name' => 'foo' + )); + + // Add an hydrator that ignores if values does not exist in the + $fieldset->setObject(new Entity\SimplePublicProperty()); + $fieldset->setHydrator(new \Zend\Stdlib\Hydrator\ObjectProperty()); + + $this->form->add($fieldset); + $this->form->setBaseFieldset($fieldset); + $this->form->setHydrator(new \Zend\Stdlib\Hydrator\ObjectProperty()); + + // Add some inputs that do not belong to the base fieldset + $this->form->add(array( + 'type' => 'Zend\Form\Element\Submit', + 'name' => 'submit' + )); + + $object = new Entity\SimplePublicProperty(); + $this->form->bind($object); + + $this->form->setData(array( + 'submit' => 'Confirm', + 'example' => array( + 'foo' => 'value example' + ) + )); + + $this->assertTrue($this->form->isValid()); + + // Make sure the object was not hydrated at the "form level" + $this->assertFalse(isset($object->submit)); + } } diff --git a/tests/ZendTest/Form/TestAsset/Entity/SimplePublicProperty.php b/tests/ZendTest/Form/TestAsset/Entity/SimplePublicProperty.php new file mode 100644 index 00000000000..78de4d19372 --- /dev/null +++ b/tests/ZendTest/Form/TestAsset/Entity/SimplePublicProperty.php @@ -0,0 +1,16 @@ +testDir) as $file) { + foreach (new DirectoryIterator($this->tmpDir) as $file) { if (!$file->isDot() && !$file->isDir()) { unlink($file->getPathname()); }