Fragmented Thought

Creating Drupal date popup fields using Drupal form api

By

Published:

Lance Gliser

Heads up! This content is more than six months old. Take some time to verify everything still works as expected.

Note that the date module is required for this form element type. An additional guide to using these elements is available on drupal.org. For a full list of options available, you'll need to check the module code itself at: date/date_api/date_api_elements.inc::_date_api_element_info()

$form['date'] = array( '#type' => 'date_popup', '#title' => t('Date'), '#date_format' => 'd-m-Y', '#date_year_range' => '-100:+0', '#date_label_position' => 'none', '#default_value' => empty($date)? '' : date('Y-m-d H:i:s', $date), );