开发者

Date of Birth drop downs in CakePHP

I am wanting to create three select boxes for a user's date of birth in a CakePHP app.

How do I do this? I have managed to build a Male or Female one using:

<?php echo $this->Form->input('gender', array('开发者_Python百科label' => '<strong>Gender</strong>', 'type' => 'select',
             'options' => array('Male'=>'Male','Female'=>'Female'))); ?>

But for a DoB one I'd need to pre-populate the fields with the month, days and year.

Can anyone help? Thanks


all you need is a DB field called "birthday" or whatever which is of type "date".

echo $this->Form->input('birthday');

thats it

i recommend adding empty=>'- -' to the options array, though.

I also use min and max for years which is quite helpful:

'minYear'=>date('Y')-USER_AGE_MAX, 'maxYear'=>date('Y')-USER_AGE_MIN+1

whereas those two constants are defined in my bootstrap. you could also use Configure::write() and read() for it. max is in my case 99 and min 9

for a "german" form it would then be

echo $this->Form->input('birthday', array('dateFormat'=>'DMY', 'minYear'=>date('Y')-USER_AGE_MAX, 'maxYear'=>date('Y')-USER_AGE_MIN+1, 'empty'=>array('- -')));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜