CakePHP HasAndBelongsToMany (HABTM) Checkboxes Instead of Multiple Select

Changing CakePHP’s default multiple select for HasAndBelongsToMany (HABTM) relationships to use multiple checkboxes used to be an arduous task. It is now a simple option as follows.

If you have a Post model that has a HABTM relationship with a Tag model, you would use the following line to display multiple checkboxes instead of the default multiple select:

<?php echo $form->input('Tag', array('multiple' => 'checkbox')); ?>

The magic is the array(‘multiple’ => ‘checkbox’).

As you probably already know, and the reason you were searching for this solution, the multiple checkboxes are much more user friendly than the multiple select.

1 comment

Comments are closed.