[Form] fixes empty file-inputs get treated as extra field

This commit is contained in:
Flavian Sierk 2013-07-25 11:50:20 +02:00 committed by Fabien Potencier
parent 2e2a36ca24
commit e5fba3cf83
2 changed files with 15 additions and 1 deletions

View File

@ -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]);
}

View File

@ -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');