diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index e151484708..43f46ca228 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -546,7 +546,7 @@ class Form implements \IteratorAggregate, FormInterface foreach ($this->children as $name => $child) { $fieldValue = null; - if (isset($submittedData[$name])) { + if (array_key_exists($name, $submittedData)) { $fieldValue = $submittedData[$name]; unset($submittedData[$name]); } diff --git a/src/Symfony/Component/Form/Tests/CompoundFormTest.php b/src/Symfony/Component/Form/Tests/CompoundFormTest.php index 71c7b2a734..34b11d3949 100644 --- a/src/Symfony/Component/Form/Tests/CompoundFormTest.php +++ b/src/Symfony/Component/Form/Tests/CompoundFormTest.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Tests; use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler; use Symfony\Component\Form\FormError; +use Symfony\Component\Form\Forms; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\Form\Tests\Fixtures\FixedDataTransformer; @@ -73,6 +74,19 @@ class CompoundFormTest extends AbstractFormTest $this->form->submit(array(), false); } + public function testSubmitDoesNotAddExtraFieldForNullValues() + { + $factory = Forms::createFormFactoryBuilder() + ->getFormFactory(); + + $child = $factory->create('file', null, array('auto_initialize' => false)); + + $this->form->add($child); + $this->form->submit(array('file' => null)); + + $this->assertCount(0, $this->form->getExtraData()); + } + public function testClearMissingFlagIsForwarded() { $child = $this->getMockForm('firstName');