2015-03-16 21:18:03 +00:00
---
title: How to add a date popup calendar onto a custom form
2015-03-17 04:04:02 +00:00
nav: blog
2015-03-31 23:05:56 +00:00
use:
- posts
2015-03-16 21:18:03 +00:00
slug: add-date-popup-calendar-custom-form
tags:
- Forms
- Form API
- Date
- Calendar
- Drupal 7
- Drupal Planet
- Drupal
---
2015-03-18 21:16:06 +00:00
First, I need to download the [Date ](http://drupal.org/project/date "Date module on Drupal.org" ) module, and make my module dependent on date_popup by adding the following line into my module's .info file.
2015-03-16 21:18:03 +00:00
dependencies[] = date_popup
Within my form builder function:
~~~php
$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()),
);
~~~