2

In a function that is a response to a drupal_get_form() I am constructing a form that includes a date field

$form['dob'] = array(
    '#type' => 'date',
    '#date_format' => 'm-d-Y',
    '#title' => 'Date of Birth',
    '#required' => TRUE,
);

This however displays the the input with year first then month and date. How can I change this to render the month first then day and then year?

1

You need to change #type value to date_select

So your code should look like this

$form['dob'] = array(
    '#type' => 'date_select',
    '#date_format' => 'm-d-Y',
    '#title' => 'Date of Birth',
    '#required' => TRUE,
);

If you want text field instead of select dropdown menu you can change date_select to date_text

  • I needed to add a '#date_year_range' to have more then the last few years but this worked, thank you! – lathomas64 Feb 13 '13 at 21:41
  • I'm glad it worked out for you. – Aboodred1 Feb 13 '13 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.