Skip to content

Commit 64eb38a

Browse files
committed
Fix disabled + SecurityComponent
Disabled inputs should be omitted from the secured fields. This will enable forms to submit successfully as long as those inputs stay excluded from the form submission. Fixes #2333
1 parent 123a1a2 commit 64eb38a

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

lib/Cake/Test/Case/View/Helper/FormHelperTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,34 @@ public function testFormSecuredRadio() {
13651365
$this->assertEquals($this->Form->fields, $expected);
13661366
}
13671367

1368+
/**
1369+
* test that forms with disabled inputs + secured forms leave off the inputs from the form
1370+
* hashing.
1371+
*
1372+
* @return void
1373+
*/
1374+
public function testFormSecuredAndDisabled() {
1375+
$this->Form->request['_Token'] = array('key' => 'testKey');
1376+
1377+
$this->Form->checkbox('Model.checkbox', array('disabled' => true));
1378+
$this->Form->text('Model.text', array('disabled' => true));
1379+
$this->Form->password('Model.text', array('disabled' => true));
1380+
$this->Form->textarea('Model.textarea', array('disabled' => true));
1381+
$this->Form->select('Model.select', array(1, 2), array('disabled' => true));
1382+
$this->Form->radio('Model.radio', array(1, 2), array('disabled' => array(1, 2)));
1383+
$this->Form->year('Model.year', null, null, array('disabled' => true));
1384+
$this->Form->month('Model.month', array('disabled' => true));
1385+
$this->Form->day('Model.day', array('disabled' => true));
1386+
$this->Form->hour('Model.hour', false, array('disabled' => true));
1387+
$this->Form->minute('Model.minute', array('disabled' => true));
1388+
$this->Form->meridian('Model.meridian', array('disabled' => true));
1389+
1390+
$expected = array(
1391+
'Model.radio' => ''
1392+
);
1393+
$this->assertEquals($expected, $this->Form->fields);
1394+
}
1395+
13681396
/**
13691397
* testDisableSecurityUsingForm method
13701398
*

lib/Cake/View/Helper/FormHelper.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ public function select($fieldName, $options = array(), $attributes = array()) {
17781778
}
17791779

17801780
if (!empty($tag) || isset($template)) {
1781-
if (!isset($secure) || $secure == true) {
1781+
if ((!isset($secure) || $secure == true) && empty($attributes['disabled'])) {
17821782
$this->_secure(true);
17831783
}
17841784
$select[] = $this->Html->useTag($tag, $attributes['name'], array_diff_key($attributes, array('name' => '', 'value' => '')));
@@ -2492,7 +2492,9 @@ protected function _generateOptions($name, $options = array()) {
24922492
*
24932493
* ### Options
24942494
*
2495-
* - `secure` - boolean whether or not the field should be added to the security fields.
2495+
* - `secure` - boolean whether or not the field should be added to the security fields.
2496+
* Disabling the field using the `disabled` option, will also omit the field from being
2497+
* part of the hashed key.
24962498
*
24972499
* @param string $field Name of the field to initialize options for.
24982500
* @param array $options Array of options to append options into.
@@ -2507,7 +2509,7 @@ protected function _initInputField($field, $options = array()) {
25072509
}
25082510

25092511
$result = parent::_initInputField($field, $options);
2510-
if ($secure === self::SECURE_SKIP) {
2512+
if (!empty($result['disabled']) || $secure === self::SECURE_SKIP) {
25112513
return $result;
25122514
}
25132515

0 commit comments

Comments
 (0)