Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP表单帮助器输入日期_Cakephp_Date_Input - Fatal编程技术网

CakePHP表单帮助器输入日期

CakePHP表单帮助器输入日期,cakephp,date,input,Cakephp,Date,Input,我认为有以下代码: $this->Form->input('born'); 这是一个日期字段,我想看看每个选择框是否可以有不同的空文本,如:[月|五][日|五][年|五] 有人遇到过这样做吗?非常感谢您的帮助。您可以这样做: echo $this->Form->input('born', array( 'label' => 'Date of birth', 'dateFormat' => 'DMY', 'minYear' => date

我认为有以下代码:

$this->Form->input('born');
这是一个日期字段,我想看看每个选择框是否可以有不同的空文本,如:[月|五][日|五][年|五]


有人遇到过这样做吗?非常感谢您的帮助。

您可以这样做:

echo $this->Form->input('born', array( 'label' => 'Date of birth', 
   'dateFormat' => 'DMY', 
   'minYear' => date('Y') - 70,
   'maxYear' => date('Y') - 18 ));
它们将是下拉列表,而不是空文本字段。您可以在此处阅读有关表单帮助器和automagic表单的更多信息:


我求助于使用jquery更新蛋糕空日期值

蛋糕:

jQuery:

$(function() {
    $('.input.date select[name$="[day]"] option[value=""]').html('-- Day --');
    $('.input.date select[name$="[month]"] option[value=""]').html('-- Month --');
    $('.input.date select[name$="[year]"] option[value=""]').html('-- Year --');
});

如果可以将输入留空,请尝试以下操作:

echo$this->Form->input('born',array('empty'=>true))

如果不是,请检查以下答案:

它有点黑,但可以做你想做的。

这对我来说很有用(cakephp2x)


您应该始终声明框架的版本,因为答案将取决于此。
$(function() {
    $('.input.date select[name$="[day]"] option[value=""]').html('-- Day --');
    $('.input.date select[name$="[month]"] option[value=""]').html('-- Month --');
    $('.input.date select[name$="[year]"] option[value=""]').html('-- Year --');
});
echo $this->Form->input('born', array( 'label' => 'Date of birth',
                                       'type'=>'date',
                                       'dateFormat'=> 'DMY',
                                       'minYear' => date('Y') - 70,
                                       'maxYear' => date('Y') - 18 ));
echo $this->Form->input('born', array( 'label' => 'Date of birth', 
   'dateFormat' => 'DMY', 
   'minYear' => date('Y') - 70,
   'maxYear' => date('Y') - 18,
   'empty' => array(
       'day' => '-- Day --', 'month' => '-- Month --', 'year' => '-- Year --',
   )
));