Merge pull request #5616 from cakephp/issue-5603

Fix radio buttons not being added to security hash.
This commit is contained in:
Mark Story 2015-01-09 15:32:44 -05:00
commit 1fee3c030e
2 changed files with 29 additions and 2 deletions

View file

@ -1338,6 +1338,18 @@ class FormHelperTest extends CakeTestCase {
$this->Form->radio('Test.test', $options);
$expected = array('Test.test');
$this->assertEquals($expected, $this->Form->fields);
$this->Form->radio('Test.all', $options, array(
'disabled' => array('option1', 'option2')
));
$expected = array('Test.test', 'Test.all' => '');
$this->assertEquals($expected, $this->Form->fields);
$this->Form->radio('Test.some', $options, array(
'disabled' => array('option1')
));
$expected = array('Test.test', 'Test.all' => '', 'Test.some');
$this->assertEquals($expected, $this->Form->fields);
}
/**
@ -1372,9 +1384,11 @@ class FormHelperTest extends CakeTestCase {
$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->text('Model.text2', array('disabled' => 'disabled'));
$this->Form->password('Model.password', array('disabled' => true));
$this->Form->textarea('Model.textarea', array('disabled' => true));
$this->Form->select('Model.select', array(1, 2), array('disabled' => true));
$this->Form->select('Model.select', array(1, 2), array('disabled' => array(1, 2)));
$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));

View file

@ -1491,7 +1491,9 @@ class FormHelper extends AppHelper {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs
*/
public function radio($fieldName, $options = array(), $attributes = array()) {
$attributes['options'] = $options;
$attributes = $this->_initInputField($fieldName, $attributes);
unset($attributes['options']);
$showEmpty = $this->_extractOption('empty', $attributes);
if ($showEmpty) {
@ -2955,7 +2957,18 @@ class FormHelper extends AppHelper {
$result = $this->addClass($result, 'form-error');
}
if (!empty($result['disabled'])) {
$isDisabled = false;
if (isset($result['disabled'])) {
$isDisabled = (
$result['disabled'] === true ||
$result['disabled'] === 'disabled' ||
(is_array($result['disabled']) &&
!empty($result['options']) &&
array_diff($result['options'], $result['disabled']) === array()
)
);
}
if ($isDisabled) {
return $result;
}