CodeIgniter Forums
Problem with form_dropdown fields - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Problem with form_dropdown fields (/showthread.php?tid=37181)



Problem with form_dropdown fields - El Forum - 12-31-2010

[eluser]caperquy[/eluser]
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.

CapErquy


Problem with form_dropdown fields - El Forum - 01-01-2011

[eluser]cLin[/eluser]
Hrm, was searching google for this as well. Anyone know?


Problem with form_dropdown fields - El Forum - 07-07-2011

[eluser]smilie[/eluser]
Better late then never...

My object $countries:

Code:
Array
(
    [0] => stdClass Object
        (
            [country] => Afghanistan
            [code] => +93
        )

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

Code:
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"');



Problem with form_dropdown fields - El Forum - 07-07-2011

[eluser]Unknown[/eluser]
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.


Problem with form_dropdown fields - El Forum - 07-07-2011

[eluser]smilie[/eluser]
what is 'same error'? Smile

My code, as stated above works as it should Smile

Show your code.


Problem with form_dropdown fields - El Forum - 07-07-2011

[eluser]ccschmitz[/eluser]
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:

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