Looking to Build/Redesign a Website or Blog ?

To speak to Rakshit, call +91 968 704 2303

Display/Show Empty Option of selectbox in CakePHP 1.3

Hello Friends,

If you are working with CakePHP than you must be aware with some syntax changes in CakePHP 1.3 with compare to CakePHP 1.2. If you are working with selectbox form automagic element in CakePHP than you might get difficulty in showing default option label. By default it shows blank value and blank label for first option of selectbox. If you want to change the empty value label from blank to "select" or any other text than here is the way to show it.

$selected = 'Option 1';
$options = array('Option 1'=>'Option 1','Option 2'=>'Option 2','Option 3'=>'Option 3');
$attributes = array('empty'=>'Select','id'=>'sel','class'=>'textbox');
echo $form->select('sel',$options,$selected,$attributes);

You just need to assign the label name in "empty" key of attributes array. If you find any problem in this than let me know by comment.


1 Comment

Leave a Reply

Your email address will not be published.