tags:

views:

288

answers:

2
$x=array('a','b','c');
echo form::dropdown('test', $x, 'b');

I'm using the Kohana form helper to build forms, but I've hit a snag. The above test code doesn't display the default value as it should, as written in the docs. Ideas?

A: 

It uses the key of the array, not the value, to determine what default value to show.

swt83
+1  A: 

Your array should be set up like this:

$x = array('a'=>'a', 'b'=>'b', 'c'=>'c');

By setting the array the way you are doing it your keys are all numeric. If you want the keys to be numeric you would need to have a number for your default value:

echo form::dropdown('test', $x, 2)

Either one of these changes would be ok depending on how you want your application set up.

slacker

related questions