diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 9f7b5340b..538d844e5 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -221,7 +221,8 @@ class FormHelper extends AppHelper { $data = $this->fieldset[$modelEntity]; $recordExists = ( isset($this->data[$model]) && - !empty($this->data[$model][$data['key']]) + !empty($this->data[$model][$data['key']]) && + !is_array($this->data[$model][$data['key']]) ); if ($recordExists) { diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index bc1683849..0dc83aed7 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -5626,6 +5626,31 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected, true); } +/** + * test that create() doesn't cause errors by multiple id's being in the primary key + * as could happen with multiple select or checkboxes. + * + * @return void + */ + function testCreateWithMultipleIdInData() { + $encoding = strtolower(Configure::read('App.encoding')); + + $this->Form->data['Contact']['id'] = array(1, 2); + $result = $this->Form->create('Contact'); + $expected = array( + 'form' => array( + 'id' => 'ContactAddForm', + 'method' => 'post', + 'action' => '/contacts/add', + 'accept-charset' => $encoding + ), + 'div' => array('style' => 'display:none;'), + 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), + '/div' + ); + $this->assertTags($result, $expected); + } + /** * test that create() doesn't add in extra passed params. *