Form Helper Keying not working as expected in some situations
Reported by merovinq | May 12th, 2011 @ 11:41 AM | in 1.3.13 (closed)
What I did
Installed a fresh cake installation to make sure it was behaving this way out of the box. Created a Testers Controller, Tester Model, and test action and view.
Setup the test action as so.
function test(){
if(isset($this->data)){
debug($this->data);
}
}
Setup the view as stated in the following post ->
http://nuts-and-bolts-of-cakephp.com/2009/03/26/saveall-with-multip...
<?php
echo $form->create();
echo $form->input('1.User.name');
echo $form->input('1.Comment.0.comment');
echo $form->input('2.User.name');
echo $form->input('2.Comment.0.comment');
echo $form->end('Save');
?>
Submitted the form.
What happened
The input tag name attribute made by the Form Helper had an extra set of keys in the beginning of the data array to be submitted, looking like so ->
When submitting the form the posted data array posted to the action also had an extra set of keys looking like so ->
caketest/controllers/testers_controller.php (line 8)
Array
(
[1] => Array
(
[1] => Array
(
[User] => Array
(
[name] =>
)
[Comment] => Array
(
[0] => Array
(
[comment] =>
)
)
)
)
[2] => Array
(
[2] => Array
(
[User] => Array
(
[name] =>
)
[Comment] => Array
(
[0] => Array
(
[comment] =>
)
)
)
)
)
What I expected to happen
I expected the input to look like so ->
I expected the data array to look like so ->
Array
(
[1] => Array
(
[User] => Array
(
[name] => bob
)
[Comment] => Array
(
[0] => Array
(
[comment] => nice guy
)
)
)
[2] => Array
(
[User] => Array
(
[name] => dave
)
[Comment] => Array
(
[0] => Array
(
[comment] => pain in the ass
)
)
)
)
Example can be found here -> http://208.64.37.102/caketest/testers/test
Comments and changes to this ticket
-

Mark Story May 12th, 2011 @ 08:31 PM
- → Milestone set to 1.3.8
- → Tag set to defect, formhelper, model, saveall
-

Ceeram May 19th, 2011 @ 04:44 PM
<?php
echo $form->create(); echo $form->input('.1.User.name'); echo $form->input('.1.Comment.0.comment'); echo $form->input('.2.User.name'); echo $form->input('.2.Comment.0.comment'); echo $form->end('Save');?>
Will output what you want:
Array
([1] => Array ( [User] => Array ( [name] => bob ) [Comment] => Array ( [0] => Array ( [comment] => bob's comment ) ) ) [2] => Array ( [User] => Array ( [name] => alan ) [Comment] => Array ( [0] => Array ( [comment] => alan's comment ) ) ))
however i noticed when adding second comment field for a user you will have to add type => text as option, as it shows an empty select input:
<?php
echo $form->create(); echo $form->input('.1.User.name'); echo $form->input('.1.Comment.0.comment'); echo $form->input('.1.Comment.1.comment', array('type' => 'text')); echo $form->input('.2.User.name'); echo $form->input('.2.Comment.0.comment'); echo $form->end('Save');?>
-

-

-

Mark Story July 2nd, 2011 @ 12:05 PM
I can confirm this is working as expected in 2.0. Helper::setEntity() is the source of this issue, but I haven't had time to fix it in 1.3
-

Jose Lorenzo Rodríguez July 27th, 2011 @ 09:36 AM
- → Milestone changed from 1.3.10 to 1.3.11
-

Jose Lorenzo Rodríguez September 18th, 2011 @ 08:35 PM
- → Milestone changed from 1.3.11 to 1.3.12
-

-

-

-

Mark Story December 10th, 2011 @ 08:37 PM
- → State changed from new to wont-fix
I'm pretty sure this is un-fixable in 1.x due to the insane way Helper::setEntity() was 'designed' to work in those versions. Closing as wontfix, as its been fixed in 2.0
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Source available from github
Repository is at http://github.com/cakephp/cakephp
Creating a bug report
When creating a bug report, please include as much relevant information as possible. Please include code to reproduce the issue. Or even better, make a unit test. Either change an existing test or add a new test to show that the expected behavior is not occuring.
People watching this ticket
Tags
Referenced by
-
#2174 Core Helper class mistakes deep associated model with an HABTM association
Fixing things in 1.3 is a bit trickier, the way setEntity...