Pavel Murnikov
Pavel Murnikov

Reputation: 113

Drupal 7 date_popup form element wrong value submitted

I"m rendering following date picker element in a custom form using Drupal 7:

    $form['navigation']['calendar_popup'] = array(
        '#type' => 'date_popup',
        '#title' => t('Date', [], $t_context),
        '#title_display' => 'invisible',
        '#default_value' => date('Y-m-d H:i:s', time()),
        '#date_format' => 'd-m-Y',
        '#size' => 10,
        '#date_label_position' => 'none', // none within
        '#date_increment' => 15,
        '#date_year_range' => '2008:+1',
        '#description' => '',
        '#required' => false,      
    );

It is November 10th today and the displayed element text is 10-11-2019. But when the form is submitted on a handheld device (I use Samsung Galaxy S5 emulation with my Chrome desktop browser), the field text briefly changes to '11-10-2019' and actually '2019-10-11' gets submitted. Same on a physical Galaxy A series handheld).

Desktop browsers don't have this issue.

Any suggestions ?

Upvotes: 0

Views: 285

Answers (1)

Fky
Fky

Reputation: 2173

Try this :

 $form['navigation']['calendar_popup'] = array(
    '#type' => 'date_popup',
    '#title' => t('Date', [], $t_context),
    '#title_display' => 'invisible',
    '#default_value' => date('Y-m-d', time()), // change format passed
    '#date_format' => 'd-m-Y',
    '#size' => 10,
    '#date_label_position' => 'none', // none within
    '#date_increment' => 15,

    '#date_timezone'       => date_default_timezone(), // add this

    '#date_year_range' => '2008:+1',
    '#description' => '',
    '#required' => false,      
);

=> force timezone + change date default value format

Upvotes: 0

Related Questions