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

Valid Date Checking

Guest
May 06, 2012 May 06, 2012

Copy link to clipboard

Copied

Hi,

I have three input boxes to allow user input the date in format dd/mm/yyyy. So, first one is used to input day, second one is month, and third one is year.

However, when I use CreateDate(form.yy, form.mm, form.dd) to form a date, it encounters error.

After testing, the error occurs because of the invalid date. For example, since default day is 31, if user set month to 4, it will show invalid date. Similar case is 31/02/2012.

Is there any checking to check the date valid?

Views

4.1K

Translate

Translate

Report

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

correct answers 1 Correct answer

Deleted User
May 07, 2012 May 07, 2012

To All,

Your discussion broaden me more in ColdFusion knowledge.

Lastly, I decide to stop the form submission if it detects the invalid date using JavaScript. This is because JavaScript can allow me to combine three textbox value into one and do the date checking.

Votes

Translate

Translate
LEGEND ,
May 06, 2012 May 06, 2012

Copy link to clipboard

Copied

Reduce the three checkboxes to one.  Use cfinput validate="date".  On the server side, use isDate() to double check.         

Votes

Translate

Translate

Report

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 ,
May 06, 2012 May 06, 2012

Copy link to clipboard

Copied

Reduce the three checkboxes to one.  Use cfinput validate="date".  On the server side, use isDate() to double check.         

Bleah. That's a pretty awful suggestion from a UX POV, Dan.

I'd perhaps use a <cfinput type="datefield"> (or - more likely - a JQuery equivalent) if I wanted a unified form control.  I'd not simply have a single input and expect the use to type it all in.

On the server side one needs to revalidate the input.  I dunno off the top of my head what string format a datefield captures the date value as, but it's probably something like mm/dd/yyyy knowing CF (experiment and find out), but I'd pull it apart and recompose it with createDate(), or perhaps parseDateTime() on it.  Either way, that could still error, so it needs to be wrapped in a try/catch, and if the operation fails, one can safely assume the exception arose because what was passed by the form wasn't valid.

CF's isDate() and isValid() date validation functions are rubbish because they will accept anything that could possible be cast as a date as valid.  So like "0" and "1,2" are dates according to CF.  Which is stupid.

--

Adam

Votes

Translate

Translate

Report

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 ,
May 07, 2012 May 07, 2012

Copy link to clipboard

Copied

Regarding, "I'd perhaps use a <cfinput type="datefield">".

Is that the one that renders as a flash movie?  If so, I think it stinks to high heaven and would never use it.  Specifically, any web form that can't be completed using only a keyboard, I consider crapware. 

This forum is a good example.  The tab key should take me out of this textarea to the Add Reply button but it doesn't.  You have to make hand movements that should be optional.

Votes

Translate

Translate

Report

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
Community Expert ,
May 07, 2012 May 07, 2012

Copy link to clipboard

Copied

Dan Bracuk wrote:

Regarding, "I'd perhaps use a <cfinput type="datefield">".

Is that the one that renders as a flash movie?  If so, I think it stinks to high heaven and would never use it.  Specifically, any web form that can't be completed using only a keyboard, I consider crapware. 

Type="datefield" is possible in both Flash and HTML forms. For the typist, it offers a text input field besides the date-picker widget.

This forum is a good example.  The tab key should take me out of this textarea to the Add Reply button but it doesn't.  You have to make hand movements that should be optional.

"This" might not be a textarea.

Votes

Translate

Translate

Report

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 ,
May 07, 2012 May 07, 2012

Copy link to clipboard

Copied

Dan Bracuk wrote:

Regarding, "I'd perhaps use a <cfinput type="datefield">".

Is that the one that renders as a flash movie?

I think you're thinking of <cfcalendar>.  That's just Flash <cfinput> will use HTML on and HTML form.

Other than that, I agree wholeheartedly with your sentiment re Flash-based forms.  It's just unnecessary 95% of the time, and is poorly implemented around 99% of the time, in my experience.

--

Adam

Votes

Translate

Translate

Report

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
Guest
May 08, 2012 May 08, 2012

Copy link to clipboard

Copied

I see the discussion mention <cfcalendar> and <cfinput type="datefield">.

I have tried the <cfinput type="datefield">. Is there any method to change the style of the calendar? For example, I want to show weekdays in white background color but show weekends in pink color. And press calendar icon can remove the calendar rather than press "cross" icon (hide the "cross" icon. Set larger text font size and so on.

Votes

Translate

Translate

Report

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 ,
May 08, 2012 May 08, 2012

Copy link to clipboard

Copied

Regarding:  "CF's isDate() and isValid() date validation functions are rubbish because they will accept anything that could possible be cast as a date as valid.  So like "0" and "1,2" are dates according to CF.  Which is stupid."

What do you do instead?

Votes

Translate

Translate

Report

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 ,
May 08, 2012 May 08, 2012

Copy link to clipboard

Copied

LATEST

Regarding:  "CF's isDate() and isValid() date validation functions are rubbish because they will accept anything that could possible be cast as a date as valid.  So like "0" and "1,2" are dates according to CF.  Which is stupid."

What do you do instead?

I disassemble the "date" into component parts; treating it as a "/" (or whatever is being used as the separator in the given situation) -delimited list, and recompose it as a date object, using createDate().  If that doesn't error: it's a date.  If it does error, I send 'em back to the form.

(Obviously the disassembly is only necessary if it's passed as one value, instead of three separate ones)

--
Adam

Votes

Translate

Translate

Report

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
Guest
May 07, 2012 May 07, 2012

Copy link to clipboard

Copied

Since there are many several pages using three textboxes to form a date, I do not prefer to combine them into one although I understand the this validation and implementation of one textbox is better than three textboxes.

Votes

Translate

Translate

Report

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
Community Expert ,
May 07, 2012 May 07, 2012

Copy link to clipboard

Copied

I think an even better solution is to combine the suggestions from Dan and Adam.

<cfform>

    <!--- Validate is necessary, for example, in case the user ignores the date picker --->

    <cfinput name="dt" type="datefield" validate="date" message="Please enter a valid date">

    <cfinput type="submit" name="sbmt" value="send">

</cfform>

Votes

Translate

Translate

Report

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
Guest
May 07, 2012 May 07, 2012

Copy link to clipboard

Copied

To All,

Your discussion broaden me more in ColdFusion knowledge.

Lastly, I decide to stop the form submission if it detects the invalid date using JavaScript. This is because JavaScript can allow me to combine three textbox value into one and do the date checking.

Votes

Translate

Translate

Report

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 ,
May 07, 2012 May 07, 2012

Copy link to clipboard

Copied

You can't just rely on clientside validation.  You need both.

--

Adam

Votes

Translate

Translate

Report

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
Documentation