Obviously it would be handy if our Fictitious Conference organizers knew when our registering speakers would be arriving for the conference. Without this information they would not be able to ensure that suitable accommodation is available and so forth.
Before we add the date component, let's add a fieldset called Arrival details
to house the speaker's planned arrival date and time fields that we're about to create.
Arrival date
and select Date from the component type list. As this is the required information, we check the Mandatory box before clicking on Add. today
. As we have chosen to use a relative date (that is, today
, whenever that may be), it is recommended that we select Website timezone
under Default value timezone.Let us know on which date will you arrive in the host city.
Arrival date
and drag it slightly to the right so that this component will render within the Arrival details
fieldset.Every time a new visitor comes to our form they will find that the current date is pre-populated into this date component. This is because we chose today's date as our default value. This could also have been left blank or set to a specific date in the future, or even the past. It is up to us to decide on something sensible to put in here.
We may find that it is sometimes easier to supply a list of of date options in the form of a select component as opposed to making use of the date component. This is especially true when we have a limited range of non-contiguous (that is, not in direct sequence) dates for our users to choose from, because we can then avoid issues around validation of the selected dates. That said, however, the date component offers a number of additional useful features.
We also have the option of limiting input to a specific range of dates. This could mean that the input has to be after a certain date, before a certain date, or somewhere in between these two extremes.
If we install and enable the Date Popup module, then we can make available to our form users a neat JavaScript pop-up calendar to ease the process of specifying the date. This is very useful from a user interface point of view as many people think better about dates when they can see a calendar.
The Date Popup comes with the Date module which can be downloaded from its home page at http://drupal.org/project/date.
PHP has a very powerful date and time function set. Thanks to this, we have great flexibility in how we specify date ranges and so on. We can learn more about the scope of what is possible by clicking on the GNU Date Input Format link that appears in various places on the Date component edit page. What we learn from that link applies to both Date and Time component types.