Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Age Verification Form - invalid date or time string

LEGEND ,
Aug 29, 2007 Aug 29, 2007
I have a form with Month + Day + Year drops downs.
User selects their DOB and if GTE 13 from NOW they're in.

Problem is if someone selects a date that doesn't exist like 9/31 CF
throws an error that I can't figure out how to
prevent - ""31/9/1976" is an invalid date or time string."

Client wants the individual drops downs. If I use a single box and
cfinputs with "date" validation it will catch these illegal dates.
Question is how can I catch them using 3 individual strings from my
m/d/y drop downs?

This is my code

<!--- Compile Form input --->
<cfset userDOB = "#form.day#/#form.month#/#form.year#">

<!--- Calculating age difference --->
<cfset userAge = datediff("yyyy",variables.userDOB, now())>
485
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 29, 2007 Aug 29, 2007
LATEST
several options to approach this:

1) using some elaborated javascript you can make sure the dates are
correlated with months and leap years, so that 31/9/1976 can't even be
selected (i.e. as soon as you select 9 as month the day field will
change to 30)
problem: clients with disabled javascript will still be able to select
wrong dates....

2) validate dates using javascript before/on form submission
problem: same elaborate js needed as in 1) and again will not work with
js disabled in browser...

3) validate dates on the server (after form submission) using cf, i.e.
inside cftry/cfcatch use createdate() or createodbcdate() functions to
try and create a date out of form values and check if it is a proper
date. do this before comparing dates. use cfthrow to throw your own
error type which you can catch with cfcatch if you want to.

--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources