Browse Source

Exclude value attribute from generated file inputs.

Having a value attribute present causes HTML validation errors in HTML5
doctypes. It has no effect in other doctypes, and excluding it is always
valid.

Fixes #3440
mark_story 13 years ago
parent
commit
2a8ebcea60

+ 4 - 0
lib/Cake/Test/Case/View/Helper/FormHelperTest.php

@@ -6018,6 +6018,10 @@ class FormHelperTest extends CakeTestCase {
 			'/div'
 		);
 		$this->assertTags($result, $expected);
+
+		$this->Form->request->data['Model']['upload'] = 'no data should be set in value';
+		$result = $this->Form->file('Model.upload');
+		$this->assertTags($result, array('input' => array('type' => 'file', 'name' => 'data[Model][upload]', 'id' => 'ModelUpload')));
 	}
 
 /**

+ 2 - 1
lib/Cake/View/Helper/FormHelper.php

@@ -1531,7 +1531,8 @@ class FormHelper extends AppHelper {
 			$this->_secure($secure, array_merge($field, array($suffix)));
 		}
 
-		return $this->Html->useTag('file', $options['name'], array_diff_key($options, array('name' => '')));
+		$exclude = array('name' => '', 'value' => '');
+		return $this->Html->useTag('file', $options['name'], array_diff_key($options, $exclude));
 	}
 
 /**