Skip to content
This repository
Browse code

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 authored
3  cake/libs/view/helpers/form.php
@@ -221,7 +221,8 @@ function create($model = null, $options = array()) {
221 221
 			$data = $this->fieldset[$modelEntity];
222 222
 			$recordExists = (
223 223
 				isset($this->data[$model]) &&
224  
-				!empty($this->data[$model][$data['key']])
  224
+				!empty($this->data[$model][$data['key']]) &&
  225
+				!is_array($this->data[$model][$data['key']])
225 226
 			);
226 227
 
227 228
 			if ($recordExists) {
25  cake/tests/cases/libs/view/helpers/form.test.php
@@ -5627,6 +5627,31 @@ function testCreateQuerystringParams() {
5627 5627
 	}
5628 5628
 
5629 5629
 /**
  5630
+ * test that create() doesn't cause errors by multiple id's being in the primary key
  5631
+ * as could happen with multiple select or checkboxes.
  5632
+ *
  5633
+ * @return void
  5634
+ */
  5635
+	function testCreateWithMultipleIdInData() {
  5636
+		$encoding = strtolower(Configure::read('App.encoding'));
  5637
+
  5638
+		$this->Form->data['Contact']['id'] = array(1, 2);
  5639
+		$result = $this->Form->create('Contact');
  5640
+		$expected = array(
  5641
+			'form' => array(
  5642
+				'id' => 'ContactAddForm',
  5643
+				'method' => 'post',
  5644
+				'action' => '/contacts/add',
  5645
+				'accept-charset' => $encoding
  5646
+			),
  5647
+			'div' => array('style' => 'display:none;'),
  5648
+			'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
  5649
+			'/div'
  5650
+		);
  5651
+		$this->assertTags($result, $expected);
  5652
+	}
  5653
+
  5654
+/**
5630 5655
  * test that create() doesn't add in extra passed params.
5631 5656
  *
5632 5657
  * @return void

0 notes on commit d56b812

Please sign in to comment.
Something went wrong with that request. Please try again.