i am generating dynamic multiple checkbox, how should i generate that and how should i manage that in cakephp?
views:
142answers:
2
+1
A:
The checkboxes should look like this:
<input name="data[ModelName][ModelName][]" value="x" id="ModelNameModeNamex" /> your Text
I created a helper for this, that renders the checkboxes in a table. It was derived from this helper
EDIT The data will be submitted as an array, that the CakeMagic can deal with. For the default example Post <-habtm-> Tag an input field in the post-view should be
<input name="data[Tag][Tag][]" value="4" id="TagTag4" /> myTagName
when submitting the data and doing a save in the PostsController, Cake will also save the habtm association in the posts_tags
table. If you are interested how exactely the data looks, simply place debug($this->data);
in the PostsController
also, 2 comments:
- If you would like some help, please put some effort in formulating the question
- It might help if you would accept an answer once in a while
harpax
2010-03-18 15:26:26
if all name check box name and id are same then how i get value of array when i submit form plz help me
dilip
2010-03-19 06:53:08
A:
Only the name attribute is really important, it decides how the data will be posted back. Getting the value of the array should be doable through $this->data
or $this->params
.
Mark Story
2010-03-22 02:01:32