In creating a drupal form, one can easily create a date field.
'#type' => 'date',
But what about a time field? Is there an easy way to create and use a drupal form field type that describes the time of day? (Something more elegant than just a textfield with the label "time"?)
Drupal 7:
date_popup in the date module makes really nice time fields You can use a form element like:
'#type' => 'date_popup',
'#date_format' => 'g:i a',
and the field will match the format you use. If you don't include date elements, it will just show time.
Actually, the date field is nothing more than a textfield with a label. That is on the outside. What you do get when using this field from the date module, is a lot of date validation, to make sure that what the user has typed/selected makes sense. The other thing you get is some different javascript tools to aid the typing of the actual date. But to do this, you need the data module.
Since time is a lot more simple (universal) than a date, you wont need much validation. So all you need, to make it into a fancy time field, is to add some javascript to help out, but this is not really needed.
So the short answer is no, you can't do something like that, but you don't really need to either. You could create your own time field with hook_elements() though if you really wanted to.
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