In drupal 7 with the date module installed, when building a form, I want to simply collect (via a form) a time for something to occur.
When using the form api, I define my field as follows
$form['dose']['time'] = array(
'#type' => 'date_popup',
'#title' => t('Start Time'),
'#date_format' => 'h:i A',
);
This shows up just fine on the screen, with the time picker I want.
When processing this in my submit function, I get no value for this form field. It is blank.
If I change this only to
$form['dose']['time'] = array(
'#type' => 'date_popup',
'#title' => t('End Date'),
'#date_format' => 'Y-m-d',
);
Then my submit function sees this form field just fine, however it also displays a date picker, which I cannot have for this field.
If I set the #required=TRUE for the first example, then validation fails, presumably because there is no Y,m,d selected. If there was a way I could set a BS value for this, I'd be ok with it as I could parse it off later.
On a sidenote, I've also tried form type date_select in much the same fashion, with the exact same blank results.
Is there any way to use the native form api in drupal and be able to actually get a time through a picker?
Looks like the Date module creates a DateObject which requires a date and time; returns the date if valid and NULL otherwise. So using the Date module functionality may not work the way you want it.
Maybe you can create the field as a regular text field and use jQuery time picker of your choice (such as http://fgelinas.com/code/timepicker/) attached to the text field as your time picker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With