I need to create a multi select form field using form helpers in cakephp.The values in the field will get populated from a table which had got a HABTM to the current model.
What is the best way to implement this?
In your ctp file:
echo $this->Form->input('Category', array(
'multiple' => 'multiple',
'type' => 'select',
));
in your action:
$cats = $this->Category->find('all');
foreach ($cats as $category) {
$categories[$category['Category']['id']] = $category['Category']['title'];
}
$this->set(compact('categories'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With