Making FormHelper clear fields on create() as well as end() this ensures that GET forms don't leak fields. Fixes #571

This commit is contained in:
mark_story 2010-06-12 22:50:09 -04:00
parent d1651db9a8
commit 50144d6b5b
2 changed files with 12 additions and 0 deletions

View file

@ -306,6 +306,7 @@ class FormHelper extends AppHelper {
unset($options['default']); unset($options['default']);
$htmlAttributes = array_merge($options, $htmlAttributes); $htmlAttributes = array_merge($options, $htmlAttributes);
$this->fields = array();
if (isset($this->params['_Token']) && !empty($this->params['_Token'])) { if (isset($this->params['_Token']) && !empty($this->params['_Token'])) {
$append .= $this->hidden('_Token.key', array( $append .= $this->hidden('_Token.key', array(
'value' => $this->params['_Token']['key'], 'id' => 'Token' . mt_rand()) 'value' => $this->params['_Token']['key'], 'id' => 'Token' . mt_rand())

View file

@ -751,6 +751,17 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
} }
/**
* test that create() clears the fields property so it starts fresh
*
* @return void
*/
function testCreateClearingFields() {
$this->Form->fields = array('model_id');
$this->Form->create('Contact');
$this->assertEqual($this->Form->fields, array());
}
/** /**
* Tests form hash generation with model-less data * Tests form hash generation with model-less data
* *