Monday, December 29, 2008

Re: checkbox groups in cakephp 1.2

thanks, thats what I was looking for. However, I'm still having
trouble getting the save to work properly.

here is the controller dump:
[data] => Array
(
[UsersEthnicity] => Array
(
[ethnicity_id] => Array
(
[0] => 1
[1] => 2
)

[users_id] => 14
)

[User] => Array
(
[age] => 21
[about_me] => adfsadfs
)

)

but I need something like this right?
[data] => Array
(
[UsersEthnicity] => Array
(
[ethnicity_id] => 1
[users_id] => 14,

[ethnicity_id] => 2
[users_id] => 14
)

[User] => Array
(
[age] => 21
[about_me] => adfsadfs
)

)

here's the controller function:
function add() {
$this->log('in newuser_controller add()');
$this->User->create();
if(!empty($this->data)) {
$this->log($this->data);
$this->log('test1');
//If the form data can be validated and saved...
if($this->User->save($this->data)) {
$this->data['UsersEthnicity']['users_id'] = $this->User->id;
$this->UsersEthnicity->save($this->data);
$this->log('test2');
//Set a session flash message and redirect.
$this->Session->setFlash("User Saved!");
//$this->redirect('newuser/add');
}
}
}

view:
<? echo $form->input('UsersEthnicity.ethnicity_id', array( 'type' =>
'select', 'multiple' => 'checkbox' ),$ethnicities); ?>

On Dec 27, 2:18 pm, "Arthur Pemberton" <pem...@gmail.com> wrote:
> On Sat, Dec 27, 2008 at 1:54 AM, mike <mwu...@gmail.com> wrote:
>
> > I saw a helper class for this for 1.1, but nothing for 1.2.
>
> > Is their an example of acheckboxgroup that maps to the same database
> > field?  for example, onecheckboxmaps to a value of 1, another maps
> > to a value of 2.
>
> http://book.cakephp.org/view/193/options-multiple
>
> --
> Fedora 9 : sulphur is good for the skin
> (www.pembo13.com)
--~--~---------~--~----~------------~-------~--~----~
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: