A time field in Drupal formats?

When creating a drupal form, it is easy to create a date field.

'#type' => 'date', 

But what about the 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 text box labeled "time"?)

+4
source share
3 answers

Actually, the date field is nothing more than a text field with a label. It is outside. What you get when using this field from a date module is a big date check to make sure what the user typed / selected makes sense. Another thing you get is various javascript tools that help print the actual date. But for this you need a data module.

Since time is much simpler (universal) than date, you don't need a lot of checking. So, all you need to turn it into a fantasy time field is to add some javascript to help, but it really is not necessary.

So, the short answer is no, you can't do something like that, but you don't need either. You can create your own hook_elements () time field, though, if you really wanted to.

+4
source

Drupal 7:

date_popup in the date module makes really nice time fields. You can use a form element, for example:

 '#type' => 'date_popup', '#date_format' => 'g:i a', 

and the field will match the format you are using. If you do not include date elements, it will simply show the time.

+6
source

There is currently no β€œstandard” solution for this, but you may find something useful in the following:

And although you do not accurately provide a time field, you may also be interested in long modules , depending on what you want to achieve.

+3
source

All Articles