diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 0e7738ee3..1058bc72f 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -1290,6 +1290,30 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * Test that a hidden field followed by a visible field + * undoes the hidden field locking. + * + * @return void + */ + public function testSecuredInputDuplicate() { + $this->Form->request['_Token'] = array('key' => 'testKey'); + $this->assertEquals(array(), $this->Form->fields); + + $this->Form->input('text_val', array( + 'type' => 'hidden', + 'value' => 'some text', + )); + $expected = array('text_val' => 'some text'); + $this->assertEquals($expected, $this->Form->fields); + + $this->Form->input('text_val', array( + 'type' => 'text', + )); + $expected = array('text_val'); + $this->assertEquals($expected, $this->Form->fields); + } + /** * Test secured inputs with custom names. * diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index b09e8e1c0..1ef91877a 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -661,6 +661,8 @@ class FormHelper extends AppHelper { if (!in_array($field, $this->fields)) { if ($value !== null) { return $this->fields[$field] = $value; + } elseif (isset($this->fields[$field]) && $value === null) { + unset($this->fields[$field]); } $this->fields[] = $field; }