I'm writing a Drupal module and have run into what should be a trivial problem;
Consider a 'Person' type node which includes a 'Date of Birth' property. I've configured the database table to use an int field to store the date in UNIX format (same as Drupal Core) but of course I need to provide a method for the user to specify the value in a more friendly format, i.e. dd/mm/yyyy.
In my modules Person_form function I have configured the date element thus:
$form['dob'] = array(
'#type' => 'date',
'#title' => 'Date of Birth',
'#required' => TRUE,
'#default_value' => array(
'day' => format_date($node->dob, 'custom', 'j'),
'month' => format_date($node->dob, 'custom', 'n'),
'year' => format_date($node->dob, 'custom', 'Y'),
),
);
which displays the UNIX date in the database in three dropdown lists, oneeach for day, month and year - this is just what I wanted, so far so good.
Now I need to be able to access this elements values when the user clicks on the 'Save' button - but I now have two problems:
- The signature of the _form function is Person_form($node) so how do I access the $form['dob']['day'/'month'/'year'] values. $form is not passed as an argument to the function.
- Once I have the values, what is the best way of generating a UNIX date value?
I've Googled about for a while but the terms 'drupal' and 'date' just seem to point me to the Date module extension - surely I don't need an extension to handle simple dates like this :-o
Thanks in advance