Cakephp-create a multi select form field

13,536

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'));
Share:
13,536
huzefam
Author by

huzefam

Into PHP

Updated on June 12, 2022

Comments

  • huzefam
    huzefam almost 2 years

    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?