If no default value is given for the date field, it is supposed to default to today's date. However, expand_date() uses !isset() to determine whether a value has been given. Since the value is an empty string when not specified, this means the date field defaults to 1 January 1900. The attached patch fixes this by replacing !isset() with empty().

CommentFileSizeAuthor
form.inc-date.patch735 bytesdarren oh

Comments

darren oh’s picture

If anyone would like to test this, I suggest trying the following code with and without the patch:

$form['date'] = array(
  '#type' => 'date'
);
$form = form_builder(NULL, $form);
$form = drupal_render($form);
echo $form;
chx’s picture

Status: Needs review » Reviewed & tested by the community

Yup.

drumm’s picture

Version: 5.x-dev » 6.x-dev

Committed to 5.

dries’s picture

Committed to CVS HEAD. Thanks.

darren oh’s picture

Status: Reviewed & tested by the community » Fixed

The Drupal 4.7 Form API works differently, so it doesn't require fixing.

Anonymous’s picture

Status: Fixed » Closed (fixed)