开发者

Remove empty value of select box

开发者 https://www.devze.com 2023-02-03 22:39 出处:网络
I have a selectbox开发者_开发百科 like this $form->select(\'city_id\',$city,array (\'empty\'=>false, \'selected\'=>\'1\',

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


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.


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

Works for me..

0

精彩评论

暂无评论...
验证码 换一张
取 消