Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP: Setting default value on a select with optgroups

On a normal select, with no optgroups, the following code in CakePHP would make a value the default one:

'selected' => $value

Once I have optgroups (a select tag with headings) how do I set a default value? The previous code doesn't seem to work.

like image 694
Chaim Avatar asked Mar 07 '11 17:03

Chaim


1 Answers

you might try it like this:

echo $this->Form->input('group_id', array('type'=>'select','default'=>'2'));

leading to the following HTML being generated:

<option value="2" selected="selected">Managers</option>

Now option two is shown instead any other one.

like image 105
benjamin Avatar answered Oct 10 '22 20:10

benjamin