Welcome Guest, Not a member yet? Register   Sign In
Form Helper : form_dropdown()
#1

[eluser]Lima[/eluser]
How can I produce dropdown box with form helper form_dropdown() like below :
Code:
<select name="foo">
<option value="0">-- All --</option>  
<optgroup label="GROUP 1">
    <option value="11">Item 11</option>
    <option value="12">Item 12</option>
    <option value="13">Item 13</option>
    <option value="14">Item 14</option>
  </optgroup>
  <optgroup label="GROUP 2">
    <option value="21">Item 21</option>
    <option value="22">Item 22</option>
    <option value="23">Item 23</option>
    <option value="24">Item 24</option>
  </optgroup>
  <optgroup label="GROUP 3">
    <option value="31">Item 31</option>
    <option value="32">Item 32</option>
    <option value="33">Item 33</option>
    <option value="34">Item 34</option>
  </optgroup>
</select>

Item with value="0" has no group.
#2

[eluser]bretticus[/eluser]
If there was an option to do opt groups, it'd be in the manual. So I really doubt you can make form_dropdown() do this.

I'd suggest writing your own helper (you can use that same function from the form helper as a template) or extending the form helper (see "Extending" Helpers.)

EDIT: Okay, well I started second guessing myself so I went and actually read the manual:

Quote:If the array passed as $options is a multidimensional array, form_dropdown() will produce an <optgroup> with the array key as the label.
#3

[eluser]Lima[/eluser]
Thanks bretticus
I know now, it needs array like this :
Code:
$data = array(
      '0' => '-- ALL --',
      'GROUP 1' => array(
          '11'  => 'Item 11',
          '12'  => 'Item 12',
          '13'  => 'Item 13',
        ),
      'GROUP 2' => array(
          '21'  => 'Item 21',
          '22'  => 'Item 22',
          '23'  => 'Item 23',
        )
      );
    echo form_dropdown('foo', $data);

CI is rock
#4

[eluser]miss_amylee[/eluser]
how to get back d value chosed from d drop down to d next page..sorry, im new in CI..
#5

[eluser]saidai jagan[/eluser]
you will get htat value using the post method while submitting the form




Theme © iAndrew 2016 - Forum software by © MyBB