本文介绍了Drupal 7日期弹出窗口默认值为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为字段集中存在的date_popup的默认值获取默认值,并且我已经遵循了其他建议,但该值始终为空。
I am trying to get a default value in for the default value of a date_popup that exists within a fieldset and I have followed the other suggestions here but the value is always blank.
$format = 'm/d/Y';
$primary_start1 = null;
if(isset($vals["primary_start"])){
if("-1" != $vals["primary_start"]){
$primary_start1 = (int)$vals["primary_start"];
}
}
$form['dates']['primary']['primary_start'] = array(
'#title' => t('Start date'),
'#name' => 'primary_start',
'#type' => 'date_popup',
'#date_timezone' => FALSE,
'#default_value' => date('m/d/Y',$primary_start1),
'#date_format' => $format,
'#required' => TRUE,
'#date_label_position' => 'none',
);
日期作为一个字符串,所以我把它转换为一个int ...我知道作品是因为我转储了变量。
The date comes in as a string, so I convert it to an int...which I know works because I dump the variable.
我在这里做错什么?
Drupal v 7.22
Drupal v 7.22
日期模块 - 7.x-2.6
Date Module - 7.x-2.6
日期弹出窗口 - 7.x-2.6
Date Popup - 7.x-2.6
推荐答案
您应该使用其他日期格式:
You should use another date format:
$format = 'Y-m-d';
同样最好使用drupal核心功能进行日期格式化:
Also it's better to use drupal core function for date formatting:
format_date($primary_start1, 'custom', $format)
这篇关于Drupal 7日期弹出窗口默认值为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!