This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
oliverdavies.uk-old-sculpin/source/_posts/2012-05-23-date-popup-custom-form.md
2015-04-11 23:21:27 +01:00

927 B

title nav use slug tags
How to add a date popup calendar onto a custom form blog
posts
add-date-popup-calendar-custom-form
forms
form-api
date
calendar
drupal-7
drupal-planet
drupal

First, I need to download the Date module, and make my module dependent on date_popup by adding the following line into my module's .info file.

dependencies[] = date_popup

Within my form builder function:

$form['date'] = array(
  '#title' => t('Arrival date'),

  // Provided by the date_popup module
  '#type' => 'date_popup',

  // Uses the PHP date() format - http://php.net/manual/en/function.date.php
  '#date_format' => 'j F Y',

  // Limits the year range to the next two upcoming years
  '#date_year_range' => '0:+2',

  // Default value must be in 'Y-m-d' format.
  '#default_value' => date('Y-m-d', time()),
);