On Apr 18, 6:24 pm, tomolang <[email protected]> wrote:
> Hi im new in cakephp. so far i like it. but i have one problem.
>
> I dont know how to create checkboxs.
>
> I have a table that called hobbies and i would like to use checkboxs
> to allow the users to select the hobbies they prefer and save this to
> a table. then later the user can go and edit the selection.
>
> how do i do this.
First, make sure your associations are correct.
User model:
var $hasAndBelongsToMany = array('Hobby');
Hobby model:
var $hasAndBelongsToMany = array('User');
In your UsersController:
function edit($id = null)
{
if (!empty($this->data))
{
...
}
/* this code will run when the user first loads the edit view,
* as well as when the save is unsuccessful and form is re-displayed
*/
$this->set(
'hobbies',
$this->User->Hobby->find('list')
);
}
view:
echo $form->input(
'Hobby',
array(
'type' => 'select',
'multiple' => 'checkbox'
),
$hobbies
);
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en