我为datepicker使用了脚本,如下所示
<script>
$(function() {
$( ".datepicker" ).datepicker({dateFormat: 'yy-mm-dd'});
$('.timepicker').timepicker({ timeFormat: 'H:mm:ss p' });
});
</script>这将在文本字段中显示
<div class="bit-4 pad-small">
<label>Trip Date</label>
<?php echo $this->Form->input('trip_date', array('label'=>false,'type' => 'text','placeholder'=>'','maxlength'=>'30','class' => 'datepicker','required')); ?>
<span>required</span>
</div>但我希望在date列中自动显示当前日期。
发布于 2015-11-30 08:26:10
可以使用php date()函数将值设置为当前日期。关于格式化选项,您可以看到以下链接:
http://php.net/manual/en/function.date.php
我想这个代码能帮到你
<?php echo $this->Form->input('trip_date',array('label'=>false,'type' =>'text','placeholder'=>'','maxlength'=>'30','class'=>'datepicker','required','value'=>date('Y-m-d')));发布于 2015-11-30 09:21:50
需要使用default属性而不是value属性来设置输入的默认值:-
<?php
echo $this->Form->input('trip_date',array(
'label' => false,
'type' => 'text',
'placeholder' => '',
'maxlength' => '30',
'class' => 'datepicker',
'required',
'default' => date('Y-m-d')
));
?>如果使用value,它将覆盖通过$this->request->data传递的任何表单数据,这通常不是所需要的。如果没有通过default传递输入,则default为输入提供一个值。如果您使用Tanbir的建议,那么如果您的表单数据中存在验证错误,则每次都会将trip_date字段重置为当前日期。
https://stackoverflow.com/questions/33994141
复制相似问题