Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing issue where an array to string conversion error could occur if…

… you had multiple values for a model's primary key and you created a matching form. Tests added.

Fixes #1257
  • Loading branch information...
commit d56b81218139db77f7fc7a75594aa97b47cc04d5 1 parent 81ce6f4
Mark Story markstory authored
3  cake/libs/view/helpers/form.php
View
@@ -221,7 +221,8 @@ function create($model = null, $options = array()) {
$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) {
25 cake/tests/cases/libs/view/helpers/form.test.php
View
@@ -5627,6 +5627,31 @@ function testCreateQuerystringParams() {
}
/**
+ * 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.
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.