tags:

views:

77

answers:

2

Hi all,

Using CakePHP, I created select-option form element with:

echo $form->select('items', $numeration , array('selected' => 0));

It creates selection box, but the first option is always empty.

How can I get rid of that empty option? I did not manage to do anything with showEmpty option...

please help.... :-((

UPDATED:

cakephp code

echo $form->select('myOptions', array(1 => 'a', 2 => 'b', 3 => 'c'), array('empty'=>false));

creates next html:

<select id="myOptions" name="data[myOptions]">
<option selected="selected" value=""></option>
<option value="1">a</option>
<option value="2">b</option>
<option value="3">c</option>
</select>

what is wrong, and why do i have empty element?!

A: 

According to the docs the third argument is the default item to be selected. If you don't want an empty option to appear change your code to:

echo $form->select('items', $numeration , NULL, array('empty' => false));
Sunny
+1  A: 

It's better to use:

$this->Form->input('items', array('options'=>$numeration));

By default it's without empty element. but to force it fully use

$this->Form->input('items', array('empty'=>false, 'options'=>$numeration));
Nik
can you please check, i updated my question with example....