0
votes

I have a selectbox like this

$form->select('city_id',$city, array ('empty'=>false, 'selected'=>'1', 'label'=> false), array('label'=>false, 'div'=>false, 'name'=>'city_id', 'id'=>'city_id'));

I need to remove the empty option at the top of my options. I even set the ''empty'=>false' but it not works!!!

Can anyone help me please

2
which version of your CakePHP? It looks like CakePHP 1.x to me. Please make sure you are looking at the correct documentation.XuDing

2 Answers

7
votes

It looks like you've messed up your arguments to $form->select().

The 1st is the field name, the 2nd is an array of key/values of select options for the user to pick from, 3rd argument should be the selected element value (or null) and the 4th the array of options, which is where you can include 'empty' => false.

select(string $fieldName, array $options, mixed $selected, array $attributes)

See the select documentation in the CakePHP Cookbook.

2
votes
<?php echo $this->Form->input('foo.bar', array('type' => 'select', 'options' => array(1 => 'foo', 2 => 'bar'), 'empty' => false)); ?>

Works for me..