Adding a date component

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.

How to do it...

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.

  1. Enter the new component name as 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.
  2. For the Default value we enter the value 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.
  3. Let's make it clear to registering speakers what we mean by arrival date by inserting the descriptive text:
    Let us know on which date will you arrive in the host city.
    
  4. The remaining options may stay as they are and we click on Save component.
  5. On the form overview page, we can click our pointer on the drag-handle next to Arrival date and drag it slightly to the right so that this component will render within the Arrival details fieldset.
  6. We must remember to click on Save to have the repositioning take effect!
How to do it...

How it works...

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.

There's more...

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.

Validating dates

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.

Providing a pop-up calendar

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.

Handling date input formats

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset