tags:

views:

268

answers:

2

Hi all,

I want the weekdays to be displayed in a drop down in cakephp, with a default day selected. My code is as follows echo $form->input('Weekday', array('options' => array ('Monday','Tuesday','Wednesday','Thursday', 'Friday','Saturday', 'Sunday'))); When I do like this it stores 0 value in database instead of day name. Also I want to set a default selected weekday . Please help!!!

Thanking you..........

A: 

you can try put an empty default by just enter like

input('field', array('options' => array(1,2,3,4,5), 'empty' =>'--choose--')); -->

u save in 0 value it might be your field is enter wrong or double check ur careless mistake. it can be properly work well in this code.

here is the link u can refer to

http://book.cakephp.org/view/201/options-empty

vincent low
+1  A: 

The options array works like array('key' => 'value'). The array key is what will be send the the sever, the value is what will be displayed in the dropdown. Since array('Monday', 'Tuesday', ...) is equivalent to array(0 => 'Monday', 1 => 'Tuesday', ...), the value you receive on the server is 0. Make your array look like array('mon' => 'Monday', 'tue' => 'Tuesday', ...) to get what you want.

To select a default option use the default parameter.

deceze