Sunday, March 29, 2009

Re: Cake PHP 1.2 - Need Help For Posting Mulitple Checkboxes

Hello,

I think you couldn't get exactly my issue that was i am facing. so
let me explain it again..

first of i don't want to create multiple check boxes by specifying
$options= array(1,2,3) at once.

i want to show multiple check boxes one by one on each row with same
name so it will automatically set name of all check boxes like
name="data[ProfilePermissionsMaster][permission][]" and it has been
done but my problem is that
it will generate hidden control for each check box on every row and
set its name without array like "data[ProfilePermissionsMaster]
[permission]" so it will only post last selected check box value only
instead of whole selected check boxes array values.

for example In another way...,

you can also check out following ticket link for same issue is here:
https://trac.cakephp.org/ticket/5577

suppose i have requirements to display check groups in split list say
that among four check boxes first i have to display two check boxes
then bla bla bla code and then again remaining want to display 3rd and
4th check boxes with same name of above check box group. It will only
post value of only last selected check boxes values only means 3rd and
4th only working..

<input type="hidden" name='data[Tag][Tag]' />
<input type="checkbox" value="1" name='data[Tag][Tag][]' />
<input type="checkbox" value="2" name='data[Tag][Tag][]' />
...
<input type="hidden" name='data[Tag][Tag]' />
<input type="checkbox" value="3" name='data[Tag][Tag][]' />
<input type="checkbox" value="4" name='data[Tag][Tag][]' />

(only checkboxes 3 and 4 are stored, because of second 'data[Tag]
[Tag]')

How to resolve this issue..? anyone have any idea or solution?

then, please let me know.

Thanks,
Keyur.
------------------------------------------------


On Mar 29, 5:43 pm, Martin Westin <martin.westin...@gmail.com> wrote:
> Cake can do all that for you in just one input unless you have some
> specific requirement I did not pick up on from your post.
>
> echo $form->input('ProfilePermissionsMaster.permission', array
> ('type'=>'select', 'value'=>array(1,2,3), 'options'=>array(1,2,3),
> 'multiple'=>'checkbox'));
>
> Notice that value is an array of values that are selected, options is
> the array of available values (one checkbox per item). This will give
> you an array like the one you want.
>
> On Mar 28, 8:55 am, keyurvaghani <keyurvagh...@gmail.com> wrote:
>
> > Hello Friends,
>
> > I am keyur vaghani and working on cake php 1.2.
>
> > Please help me out from following issue on cake php 1.2 related to
> > post values of selected multiple check boxes.
>
> > I want to list multiple check boxes with same name on different rows
> > and post its values as array with selected (checked) check boxes, but
> > it couldn't and only get post value as last selected control check box
> > element value.
>
> > Because It will generate auto hidden element with each different row
> > check box control and here the original check box control name is
> > generated with array and it is correct like [Model][fieldname][] but
> > it couldn't generate this array name of hidden control that's why i am
> > facing major trouble while posting.
>
> > for example,
> > <?php
>
> > $options=array(1=>" Test Check Box Option1");
> > e($form->select('ProfilePermissionsMaster.permission',
> > $options,NULL,array('multiple'=> 'checkbox' , 'separator'=>' <br>
> > ','value'=>'1')));
>
> > $options2=array(1=>" Test Check Box Option2");
> > e($form->select('ProfilePermissionsMaster.permission',
> > $options2,NULL,array('multiple'= >'checkbox' , 'separator'=>' <br>
> > ','value'=>'2')));
>
> > $options3=array(1=>" Test Check Box Option3");
> > e($form->select('ProfilePermissionsMaster.permission',
> > $options,NULL,array('multiple'=> 'checkbox' , 'separator'=>' <br>
> > ','value'=>'3')));
>
> > ?>
>
> > It want post values like as below, but couln't get it ??
>
> > Array( [ProfilePermissionsMaster] =>Array(
>
> > [permission] => Array
> > (
> > [0] => 1
> > [1] => 2
> > [2] => 3
> > )
>
> > )
>
> > )
>
> > as well as when ever i set value attribute, it will display checked
> > check box why?
>
> > Thanks and Regards,
> > Keyur.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: