Date fields

Component ID

2623822

Component name

Date fields

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Downloads

838

Component created

Component changed

Component body

Description

A simple Form API widget for entering date data using separate text fields for day, month and year. The format of the field uses the site's configured date format in exactly the same way as the default date widget does.

The field supports a #mindate and #maxdate attribute for server side validation. Support for clientside validation, including ensuring dates are valid (e.g. 2015-02-29 will not validate) will be added soon(ish).

Configuration example

$form['date_of_birth'] = array(
  '#title' => t('Date of birth'),
  '#type' => 'date_fields',
  '#required' => TRUE,
  '#mindate' => strtotime((date('Y') - 100) . date('-m-d')),
  '#maxdate' => time(),
  '#mindate_error' => t('Please enter a date within the last 100 years.),
  '#mindate' => strtotime((date('Y') - 100) . date('-m-d')),
  '#maxdate_error' => t('Please enter a date up to and including today.),
);

Screenshot