phpcodeignitervalidationcodeigniter-form-helper

how to create a multi select box with out selected options codeigniter


hi i am using codeigniter , i want to add a multi select box to my page ,

i saw the codeigniter user guide example , but what it is doing is set the values in multi select .

like this

$options = array(
                  'small'  => 'Small Shirt',
                  'med'    => 'Medium Shirt',
                  'large'   => 'Large Shirt',
                  'xlarge' => 'Extra Large Shirt',
                );

$shirts_on_sale = array('small', 'large');

echo form_dropdown('shirts', $options, $shirts_on_sale);

in this multi select box created like this

<select name="shirts" multiple="multiple">
<option value="small" selected="selected">Small Shirt</option>
<option value="med">Medium Shirt</option>
<option value="large" selected="selected">Large Shirt</option>
<option value="xlarge">Extra Large Shirt</option>
</select>

it have to give the options to be selected in $shirts_on_sale array , but in my case i want to create a multi select but dont want selected options i tried to pass an empty array . but it is not working

like this

$array = array();
echo form_dropdown('shirts', $substore_details, $array); 

how to create a multi select with no selected items . please help..............


Solution

  • You should use the form_multiselect() helper.

    $options = array(
                      'small'  => 'Small Shirt',
                      'med'    => 'Medium Shirt',
                      'large'   => 'Large Shirt',
                      'xlarge' => 'Extra Large Shirt',
                    );
    
    echo form_multiselect('shirts', $options);