Jump to content

Best way to take date input from user?


AlphaWolf

Recommended Posts

Hi,

I'm using the form data type 'date', and trying to verify it. It seems a little too complicated to check that it's in the correct format (with "/" between day/month/year), unless I use regular expression, which I don't know much about and seems feels like there's an alternate solution or it's not necessary. Currently, the script accepts DD*MM*YYYY, where * is any character, since it just strips the 3rd and 6th character and checks the day/month/year using checkdate().

I'm not even sure if this is a problem. I am giving the user a "verify" page, where I could put it in the correct format (DD/MM/YYYY), but is that enough?

Feel like I'm missing something here, so any feedback would be great :)

Link to comment
https://forums.phpfreaks.com/topic/254141-best-way-to-take-date-input-from-user/
Share on other sites

Just use 3 input boxes

 

 

<form method="post">
Date (d/m/Y): <input size="2" maxlength="2" title="Day of month" name="day" > <input size="2" maxlength="2" title="Month of year" name="month" > <input size="4" maxlength="4" title="Year" name="Year" >
</form>

 

I also like to use jQuery mouse wheel to scroll through days/months/years and a pop-up calendar, I wrote an extension to do both but it's on my work computer :(

The 'best' approach, IMHO, is to use a jQuery datepicker, with <select> fields as the <noscript> backup, using the names of the months as the label part of the <option>s, then just use checkdate to validate the input.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.