Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'release'

  • Loading branch information...
commit 871401ef8f22b84c131f39ad4462089c1809e5d9 2 parents bfae3dd + 74ed4f4
@weierophinney weierophinney authored
Showing with 23 additions and 0 deletions.
  1. +6 −0 library/Zend/Form/Form.php
  2. +17 −0 tests/ZendTest/Form/FormTest.php
View
6 library/Zend/Form/Form.php
@@ -137,6 +137,12 @@ public function add($elementOrFieldset, array $flags = array())
$elementOrFieldset = $factory->create($elementOrFieldset);
}
+ // check if the element is a file and add enctype attribute if so
+ $type = $elementOrFieldset->getAttribute('type');
+ if (isset($type) && $type === 'file') {
+ $this->attributes['enctype'] = 'multipart/form-data';
+ }
+
parent::add($elementOrFieldset, $flags);
if ($elementOrFieldset instanceof Fieldset && $elementOrFieldset->useAsBaseFieldset()) {
View
17 tests/ZendTest/Form/FormTest.php
@@ -286,6 +286,23 @@ public function testCanRetrieveDataWithoutErrorsFollowingValidation()
$this->assertInternalType('array', $data);
}
+ /**
+ * @group ZF2-336
+ */
+ public function testCanAddFileEnctypeAttribute()
+ {
+ $this->form->add(array(
+ 'name' => 'file_resource',
+ 'attributes' => array(
+ 'label' => 'This is a file',
+ 'type' => 'file',
+ )));
+
+ $enctype = $this->form->getAttribute('enctype');
+ $this->assertNotEmpty($enctype);
+ $this->assertEquals($enctype, 'multipart/form-data');
+ }
+
public function testCallingGetDataReturnsNormalizedDataByDefault()
{
$this->populateForm();
Please sign in to comment.
Something went wrong with that request. Please try again.