Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove the wrapping div from a Form input of type select-multiple

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.

like image 392
himanshu dhiman Avatar asked Mar 03 '12 11:03

himanshu dhiman


2 Answers

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

like image 178
mehov Avatar answered Oct 22 '22 03:10

mehov


Taking a look at the API, you can use the after and before array options to control what goes before and after the <input> and <label> pair. Here is the documentation on the input function or the API

Alternatively, you you could use the checkbox function (API) in the Form helper to get around it

like image 31
Ryan Gibbons Avatar answered Oct 22 '22 02:10

Ryan Gibbons