diff --git a/cake/libs/controller/components/security.php b/cake/libs/controller/components/security.php index b87ffdbf0..86ab565f3 100644 --- a/cake/libs/controller/components/security.php +++ b/cake/libs/controller/components/security.php @@ -517,6 +517,10 @@ class SecurityComponent extends Object { if (!isset($controller->data[$newKey])) { $controller->data[$newKey] = array(); + + if (array_keys($controller->data[$key]) === array($newKey)) { + $field[$newKey] = array($newKey); + } } if (is_array($value)) { @@ -545,12 +549,11 @@ class SecurityComponent extends Object { unset($controller->data[$key]); continue; } - if (!array_key_exists($key, $value)) { - if (isset($field[$key])) { - $field[$key] = array_merge($field[$key], array_keys($value)); - } else { - $field[$key] = array_keys($value); - } + + if (isset($field[$key])) { + $field[$key] = array_merge($field[$key], array_keys($value)); + } else { + $field[$key] = array_keys($value); } } diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 8fd7e23e3..38d7c069a 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1198,6 +1198,9 @@ class Model extends Overloadable { foreach ($joined as $assoc => $value) { $newValues = array(); + if (empty($value)) { + $value = array(); + } if (isset($this->hasAndBelongsToMany[$assoc])) { list($join) = $this->joinModel($this->hasAndBelongsToMany[$assoc]['with']); $conditions = array($join . '.' . $this->hasAndBelongsToMany[$assoc]['foreignKey'] => $id); diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 959358425..1fead6294 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -758,22 +758,22 @@ class FormHelper extends AppHelper { function radio($fieldName, $options = array(), $attributes = array()) { $attributes = $this->__initInputField($fieldName, $attributes); $this->__secure(); - $legend = false; + if (isset($attributes['legend'])) { $legend = $attributes['legend']; unset($attributes['legend']); } elseif (count($options) > 1) { $legend = __(Inflector::humanize($this->field()), true); } - $label = true; + if (isset($attributes['label'])) { $label = $attributes['label']; unset($attributes['label']); } - $inbetween = null; + if (isset($attributes['separator'])) { $inbetween = $attributes['separator']; unset($attributes['separator']); @@ -784,25 +784,29 @@ class FormHelper extends AppHelper { } else { $value = $this->value($fieldName); } - $out = array(); + foreach ($options as $optValue => $optTitle) { $optionsHere = array('value' => $optValue); + if (isset($value) && $optValue == $value) { $optionsHere['checked'] = 'checked'; } $parsedOptions = $this->_parseAttributes(array_merge($attributes, $optionsHere), array('name', 'type', 'id'), '', ' '); $tagName = Inflector::camelize($this->model() . '_' . $this->field() . '_'.Inflector::underscore($optValue)); + if ($label) { $optTitle = sprintf($this->Html->tags['label'], $tagName, null, $optTitle); } $out[] = sprintf($this->Html->tags['radio'], $attributes['name'], $tagName, $parsedOptions, $optTitle); } $hidden = null; - if (!isset($value)) { + + if (!isset($value) || $value === '') { $hidden = $this->hidden($fieldName, array('value' => '', 'id' => $attributes['id'] . '_'), true); } $out = $hidden . join($inbetween, $out); + if ($legend) { $out = sprintf($this->Html->tags['fieldset'], $legend, $out); } @@ -868,7 +872,7 @@ class FormHelper extends AppHelper { $key = '_' . $model; if (isset($this->params['_Token']) && !empty($this->params['_Token'])) { - $options['name'] = str_replace($model, $key, $options['name']); + $options['name'] = preg_replace("/$model/", $key, $options['name'], 1); } if (!empty($options['value']) || $options['value'] === '0') { @@ -1034,10 +1038,10 @@ class FormHelper extends AppHelper { if ($attributes['multiple'] === 'checkbox') { $tag = $this->Html->tags['checkboxmultiplestart']; $style = 'checkbox'; - $select[] = $this->hidden(null, array('value' => '')); } else { $tag = $this->Html->tags['selectmultiplestart']; } + $select[] = $this->hidden(null, array('value' => '')); } else { $tag = $this->Html->tags['selectstart']; } diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index e2388de13..7f6647631 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -777,9 +777,9 @@ class FormHelperTest extends CakeTestCase { function testSelectMultiple() { $result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), null, array('multiple' => true)); - $this->assertPattern('/^]+name="data\[Model\]\[multi_field\]\[\]"[^<>\/]*>/', $result); - $this->assertPattern('/^]+id="ModelMultiField"[^<>\/]*>/', $result); - $this->assertPattern('/^]+multiple="multiple"[^<>\/]*>/', $result); + $this->assertPattern('/^]+ \/>\s*]+name="data\[Model\]\[multi_field\]\[\]"[^<>\/]*>/', $result); + $this->assertPattern('/^]+ \/>\s*]+id="ModelMultiField"[^<>\/]*>/', $result); + $this->assertPattern('/^]+ \/>\s*]+multiple="multiple"[^<>\/]*>/', $result); $this->assertNoPattern('/^]+[^name|id|multiple]=[^<>\/]*>/', $result); $this->assertNoPattern('/option value=""/', $result); $this->assertNoPattern('/selected/', $result); @@ -790,7 +790,7 @@ class FormHelperTest extends CakeTestCase { $this->assertPattern('/<\/select>$/', $result); $result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), null, array('multiple' => 'multiple')); - $this->assertPattern('/^]+multiple="multiple"[^<>\/]*>/', $result); + $this->assertPattern('/^]+ \/>\s*]+multiple="multiple"[^<>\/]*>/', $result); $this->assertNoPattern('/^]+[^name|id|multiple]=[^<>\/]*>/', $result); $result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array(0, 1), array('multiple' => true)); @@ -1406,10 +1406,10 @@ class FormHelperTest extends CakeTestCase { $this->Form->create(); $result = $this->Form->select('People.People', $options, null, array('multiple' => true)); - $this->assertPattern('/^]+>\s*(]+>.+<\/option>\s*){3}<\/select>$/', $result); - $this->assertPattern('/^]+name="data\[People\]\[People\]\[\]"[^<>]*>/', $result); - $this->assertPattern('/^]+multiple="multiple"[^<>]*>/', $result); - $this->assertPattern('/^]+id="PeoplePeople"[^<>]*>/', $result); + $this->assertPattern('/^]+ \/>\s*]+>\s*(]+>.+<\/option>\s*){3}<\/select>$/', $result); + $this->assertPattern('/^]+ \/>\s*]+name="data\[People\]\[People\]\[\]"[^<>]*>/', $result); + $this->assertPattern('/^]+ \/>\s*]+multiple="multiple"[^<>]*>/', $result); + $this->assertPattern('/^]+ \/>\s*]+id="PeoplePeople"[^<>]*>/', $result); $this->assertNoPattern('/]+[^id|name|multiple]=[^<>]*>$/', $result); } @@ -1589,7 +1589,7 @@ class FormHelperTest extends CakeTestCase { $result = $this->Form->input('MyOther.id'); $this->assertEqual($result, ''); } - + function testDbLessModel() { $this->Form->create('TestMail');