Drupal 7日期弹出默认值为空白 [英] Drupal 7 date popup default value is blank

查看:20
本文介绍了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日期弹出默认值为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆