CakePHP: $ this-> Form-> input () - How to set the default selection option

In my opinion, I have:

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

and outputs:

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

but how can I tell it input () that I want the default option like this :?

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

nvm found this:

echo $this->Form->input('category_parent_id', array('empty' => 'Select a parent category'));
+3
source share
1 answer

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

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

EDIT

In your editing, to enable the empty option by default, do it as described in the CakePHP Form Helper ...

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

All Articles