mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
a44d17dbfa
commit
143c34bdc1
2 changed files with 26 additions and 0 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue