Drupal 7 date popup default value is blank

左心房为你撑大大i 提交于 2019-12-25 05:28:31

问题


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',


);

The date comes in as a string, so I convert it to an int...which I know works because I dump the variable.

Am I doing anything wrong here?

Drupal v 7.22

Date Module - 7.x-2.6

Date Popup - 7.x-2.6


回答1:


You should use another date format:

$format = 'Y-m-d';

Also it's better to use drupal core function for date formatting:

format_date($primary_start1, 'custom', $format)


来源:https://stackoverflow.com/questions/16484852/drupal-7-date-popup-default-value-is-blank

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!