Using the Date Widget with Drupal's Form API
I recently had to use the Date module in a custom booking form that was constructed using Drupal's awesome Form API. Now I'm sure someone is going to come along and prove me wrong but I couldn't find any documentation on the available widget types, form properties or much of anything to be honest. I did find a few wrong examples that were doing some weird hacks like overwriting #process. Here are a few examples to get you going with the Drupal Date widget that I found by digging through code, looking at other modules and just outright guessing. Below shows how to:
- Select box Drupal date widget
- Set the date format
- Set the date year range
- Set the date minute increment
<?php $form['custom_date_field'] = array( // The drop down select widget. '#type' => 'date_select', // This follows PHP's standard date letters. This is the format // that will be outputted. '#date_format' => 'd m Y H i', // The first number is how many years to go back, and the second forward. '#date_year_range' => '-0:+1', // The minute increment. '#date_increment' => '15', ); ?>
As I find any more attributes and their interesting formats i'll be sure to post back.