Handle case where a visible input shares a name with an invisible one.

If a visible input is created *after* a hidden input was created, the
form would always blackhole unless the visible input had the same value
as the hidden input.

Refs #7274
This commit is contained in:
mark_story 2015-08-22 23:10:44 -04:00
parent a44d17dbfa
commit 143c34bdc1
2 changed files with 26 additions and 0 deletions

View file

@ -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.
*

View file

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