开发者

How to get weekdays in drop down in cakephp, with a default day selected?

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 def开发者_StackOverflow社区ault selected weekday . Please help!!!

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


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.


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


I recommend using something like jQuery UI, or some other JS plugin for example and their DatePicker. It is really useful, in their web page there are a lot of examples so you can do it really fast and easy. I did it so time ago and I was really pleased from the result :)

Check this link : http://jqueryui.com/datepicker/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜