Welcome Guest, Not a member yet? Register   Sign In
Problem with form_dropdown fields

I am generating a drop-down field using form_dropdown. The result I get is something like this :

<option value="0">January</option>
<option value="1">February</option>
<option value="2">March</option>

The only problem I have is that when my controller receives the selected value, 1 for example, I do not know how to catch the string February which is associated with it. I thought that It might possible to generate something like

<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
but I do not know how to do that.

Many thanks to whoever can help.


Hrm, was searching google for this as well. Anyone know?

Better late then never...

My object $countries:

    [0] => stdClass Object
            [country] => Afghanistan
            [code] => +93

    [1] => stdClass Object
            [country] => Albania
            [code] => +355

foreach($countries as $key=>$val)
    $country_list[$val->country] = $val->country;
echo form_dropdown('main_c_country',$country_list,$data->main->country,'style="width:auto;" id="main_c_country"');

I just tried the code and still getting the same error. I wonder how to capture this with just simple coding. I know how to get this working but I need to code it like twice the lenght of the entire code. It involves complex algorithm but for sure this can be captured easily.

what is 'same error'? Smile

My code, as stated above works as it should Smile

Show your code.

It uses the keys from the array you specify so make sure you are using an associate array, otherwise I think it will use numbers by default.

Try this:

$options = array(
    'January' => 'January',
    'February' => 'February',
    'March' => 'March'
echo $form_dropdown('month', $options);

Theme © iAndrew 2016 - Forum software by © MyBB