Skip to content

Commit

Permalink
[Form] fixes empty file-inputs get treated as extra field
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavian Sierk authored and fabpot committed Jul 26, 2013
1 parent 2e2a36c commit e5fba3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/Form.php
Expand Up @@ -546,7 +546,7 @@ public function submit($submittedData, $clearMissing = true)

foreach ($this->children as $name => $child) {
$fieldValue = null;
if (isset($submittedData[$name])) {
if (array_key_exists($name, $submittedData)) {
$fieldValue = $submittedData[$name];
unset($submittedData[$name]);
}
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/Form/Tests/CompoundFormTest.php
Expand Up @@ -13,6 +13,7 @@

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;
Expand Down Expand Up @@ -73,6 +74,19 @@ public function testSubmitDoesNotSaveNullIfNotClearMissing()
$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');
Expand Down

0 comments on commit e5fba3c

Please sign in to comment.