php - 我如何限制用户可以在 CakePHP FormHelper 的日期字段中选择的日期?

标签 php date cakephp formhelper

我想将用户对日期的选择限制为仅限星期一。

我将日期字段存储在 MySQL 数据库中,当我使用 echo $this->Form->input('date');< 时,CakePHP 会自动在添加/编辑表单上为我生成一个日期选择器。但它会生成年、月和日的下拉菜单。这似乎不是将用户选择限制在每月四到五天的好方法。

我已经查看了 options available for the datetime input field在 CakePHP 站点上,interval 与我需要的完全一样,但它仅适用于日期时间字段上的分钟框,并且似乎对日期字段没有影响。

是否有一个干净的 CakePHP 方法来解决这个问题,还是我自己生成日期列表并创建一个包含这些值的下拉框?

谢谢!

最佳答案

如果你想拥有一个漂亮的 UI,请使用 Jquery DatePicker

//Cake view
    echo $this->Form->input('created', array('type'=>'text', 'id'=>'created'));

//Jquery 
    $('#created').datepicker({
         dateFormat : 'yy-mm-dd'
    });   

否则你可以限制日期输入

//Year
echo $this->Form->year('purchased-year', 2000, date('Y'));
//Month
echo $this->Form->month('mob');
//Day
echo $this->Form->day('created');

FormHelper::hour(string $fieldName, boolean $format24Hours, array $attributes)
Creates a select element populated with the hours of the day.

FormHelper::minute(string $fieldName, array $attributes)
Creates a select element populated with the minutes of the hour.

FormHelper::meridian(string $fieldName, array $attributes)
Creates a select element populated with ‘am’ and ‘pm’.

http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#creating-date-and-time-inputs

关于php - 我如何限制用户可以在 CakePHP FormHelper 的日期字段中选择的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22842442/

相关文章:

php - 获取某个日期范围内的所有表格

PHP CURL 似乎忽略了 cookie jar/文件

ruby-on-rails - 如果今天显示 Rails created_at?

php - Cakephp 的 beforeSave 在使用 saveAll 时不保留新数据?

javascript - 为什么我想运行 Coffeescript cake 命令时却运行了 CakePHP 的 cake 命令?

cakephp 3 多级关联保存

php - 如何使用 wp_query 搜索带空格和不带空格的英国邮政编码?

php - 从php中获取python脚本的返回值

javascript - 如何在 JavaScript 中为一个非常旧的日期(大约公元 0 年)格式化初始化字符串?

php - 见过的功能,就像这里一样