diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 3e3ff9510..778c1925d 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -1365,6 +1365,34 @@ class FormHelperTest extends CakeTestCase { $this->assertEquals($this->Form->fields, $expected); } +/** + * test that forms with disabled inputs + secured forms leave off the inputs from the form + * hashing. + * + * @return void + */ + public function testFormSecuredAndDisabled() { + $this->Form->request['_Token'] = array('key' => 'testKey'); + + $this->Form->checkbox('Model.checkbox', array('disabled' => true)); + $this->Form->text('Model.text', array('disabled' => true)); + $this->Form->password('Model.text', array('disabled' => true)); + $this->Form->textarea('Model.textarea', array('disabled' => true)); + $this->Form->select('Model.select', array(1, 2), array('disabled' => true)); + $this->Form->radio('Model.radio', array(1, 2), array('disabled' => array(1, 2))); + $this->Form->year('Model.year', null, null, array('disabled' => true)); + $this->Form->month('Model.month', array('disabled' => true)); + $this->Form->day('Model.day', array('disabled' => true)); + $this->Form->hour('Model.hour', false, array('disabled' => true)); + $this->Form->minute('Model.minute', array('disabled' => true)); + $this->Form->meridian('Model.meridian', array('disabled' => true)); + + $expected = array( + 'Model.radio' => '' + ); + $this->assertEquals($expected, $this->Form->fields); + } + /** * testDisableSecurityUsingForm method * diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 5498f2db8..f67f7a359 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1778,7 +1778,7 @@ class FormHelper extends AppHelper { } if (!empty($tag) || isset($template)) { - if (!isset($secure) || $secure == true) { + if ((!isset($secure) || $secure == true) && empty($attributes['disabled'])) { $this->_secure(true); } $select[] = $this->Html->useTag($tag, $attributes['name'], array_diff_key($attributes, array('name' => '', 'value' => ''))); @@ -2492,7 +2492,9 @@ class FormHelper extends AppHelper { * * ### Options * - * - `secure` - boolean whether or not the field should be added to the security fields. + * - `secure` - boolean whether or not the field should be added to the security fields. + * Disabling the field using the `disabled` option, will also omit the field from being + * part of the hashed key. * * @param string $field Name of the field to initialize options for. * @param array $options Array of options to append options into. @@ -2507,7 +2509,7 @@ class FormHelper extends AppHelper { } $result = parent::_initInputField($field, $options); - if ($secure === self::SECURE_SKIP) { + if (!empty($result['disabled']) || $secure === self::SECURE_SKIP) { return $result; }