SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date Form Fields

    I have a "Date of Birth" field for a register form, what would somebody recommend the best, simplest method for users to enter their date of birth whilst allowing for easy entry into the database.

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code HTML4Strict:
    <label for="dob">Date of birth</label>
    <input type="text" name="dob" id="dob">
    Then use a validation that accepts different formats. The main problem will be ambiguous dates if you have both American users and users from other parts of the world.
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Member
    Join Date
    Oct 2008
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I already have almost that exact code, my problem is finding the best way to take what the user inputs and storing it into the database correctly.

    I have looked at the 'date picker'-style method where the user selects the date from a sort of pop-up box, which I believe is done with JavaScript? What do you think?

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Those can be useful, of course, but they should be an available feature, not the sole means of specifying the date. Otherwise you lock out everyone who doesn't have JavaScript enabled or sits behind a firewall that blocks all incoming JavaScript.

    Depending on where your target audience is, you could state that the date should be specified as YYYYMMDD (ISO 8601 standard), DDMMYYYY (common European format) or MMDDYYYY (U.S. format). Then you should accept various types of separators, so that a user can type in 08052009, 08.05.2009, 08/05/2009, 8.5.2009, 8/5/2009, etc. And for improved user-friendliness, accept also 2-digit years, like 080509 or 8/5/09.

    As an example, we have a number of date fields on our intranet. In Sweden we generally use the ISO 8601 standard format, e.g., 2009-05-08. But I'll accept other separators and also 2-digit years, so a user could enter 2009/05/08 or 090508 or 09.05.08 and it would still work. Fortunately, I don't have to worry about the odd US format, though.
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •