steve
steve

Reputation: 35

cakePHP: $this->Form->input() - How to set a select default option

In my view I have:

echo $this->Form->input('category_parent_id');

and it outputs:

<option value="1">category name 1</option>
<option value="2">category name 2</option>
...

but how do I tell it input() that I want a default option like so?:

<option value="">select a category</option>
<option value="1">category name 1</option>
<option value="2">category name 2</option>
...

nvm, found it:

echo $this->Form->input('category_parent_id', array('empty' => 'Select a parent category'));

Upvotes: 3

Views: 17899

Answers (1)

Scott Harwell
Scott Harwell

Reputation: 7465

Your question is a little vague, but you can do the following to select a default option...

echo $this->Form->input('category_parent_id', array('default' => 'id_of_default_val'));

EDIT

Per your edit, to include an empty default option, do this as documented in the CakePHP Form Helper...

echo $this->Form->input('category_parent_id', array('empty' => 'choose one'));

Upvotes: 15

Related Questions