I have two tables in my database "cars" and "car_types". "cars" table refers to "car_types" by "car_type_id". For example "car_types" has 2 fields "id" and "car_type". It also has 3 entries "new", "used dealer", "used private". How can I show these 3 entries as checkbox in my view.
I'm trying to adjust the output from:
foreach ($car_types as $car_type)
{
$car_type_new[$car_type['CarType']['id']]=$car_type['CarType']['car_type'];
}
echo $this->Form->input('Car.car_type_id',array('div'=>false,'multiple'=>'checkbox','options'=>$car_type_new,'style'=>"margin-left:20px; padding:0;"));
I also want to remove the wrapper div around each checkbox.
Each checkbox is output by the Form helper like so, even if the div => false option is set:
<input type="hidden" id="CarCarTypeId" value="" name="data[Car][car_type_id]">
<div class="checkbox"><input type="checkbox" id="CarCarTypeId1" value="1" name="data[Car][car_type_id][]"><label for="CarCarTypeId1">New</label></div>
<div class="checkbox"><input type="checkbox" id="CarCarTypeId2" value="2" name="data[Car][car_type_id][]"><label for="CarCarTypeId2">Used Dealer</label></div>
<div class="checkbox"><input type="checkbox" id="CarCarTypeId3" value="3" name="data[Car][car_type_id][]"><label for="CarCarTypeId3">Used Private
</label></div>
the div => false option only removes the div wrapped around the entire collection of checkboxes, not each checkbox.
Any Ideas on how I could remove the div that wraps around each checkbox? And please do tell me if I am doing it wrong.
I know the question is about CakePHP 1.3, but I found this while searching on the Internet, so I'll share the solution that worked for me anyway.
You can pass a corresponding key to the $options
for the input()
helper function:
'div'=>false
More info: http://api.cakephp.org/2.5/class-FormHelper.html#_input