0

Hi,
I am forced to use the old style validation for some basic form elements, and I am having problems with a date input box, I figured that it automatically stores the value as a String so the "AND isDate(form.Effective_Date)" should return a true or false, what it does instead return a blank space that ends up passing my initial validation .

I guess me question is, I am grabbing a value from a form (YYYYMMDD) which I need converted to number and/or then checked for valid, present and non space value.

<p><label for="Effective_Date">Effective Date of the assignment (yyyymmdd):</label><br />
	<input type="text" class="date" maxlength="8" value="" id="Effective_Date" name="Effective_Date" tabindex="1400" /></p>
<cfif ISDEFINED("form.Effective_Date")>
	<cfset Effective_Date = Trim(form.Effective_Date)>
<cfelse>
	  <cfset Effective_Date = "">
</cfif>
<cfif NOT ISDEFINED("form.Effective_Date") OR form.Effective_Date EQ "">
	<cfset errors = errors & "<li class=""errors"">Effective Date</li>">
</cfif>
2
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by arrgh
0

<cfif NOT ISDEFINED("form.Effective_Date")>

Text fields always exist. So IsDefined will do nothing.

the "AND isDate(form.Effective_Date)" should return a true or false

It will, but the code's not using IsDate ;-) It's checking if the value is an empty string "". Trim() the field and use IsDate instead.

Edited by arrgh: n/a

0

thanks guys, will give all this a go, and I didn't know that about isDefined..seems pointless now.

0
<cfif TRIM(form.Effective_Date) NEQ "" AND isDate(TRIM(form.Effective_Date))>
	<cfset Effective_Date = TRIM(form.Effective_Date)>
<cfelse>
	  <cfset errors = errors & "<li class=""errors"">Effective Date</li>">
</cfif>

So, if I put numeric value into the form field, it keeps failing since it's stored as a string, how do I convert it to pure numeric before making any validation onto it? Otherwise the trim works awesome, and isDefined is useless as stated...

0

That's not why it's failing. Just about everything is stored as a string in CF. Trimming only removes leading/trailing white space. If the field has any other value, it'll be evaluated by IsDate. So trimming does not buy you much here either.

What's an example of these "numeric" date values that are failing? Seems like you're trying to pass in something isDate doesn't understand.

isDefined is useless

With forms it's useful for checkboxes, radio buttons or multi-select lists. ie Fields that don't always exist.

Edited by arrgh: n/a

0

well, I have tried any type of input but the ideal is that if they enter (numeric) yyyymmddd (20110224). Since it is being examined as string, isDate is not working.

html form code below:

<input type="text" class="date" maxlength="8" value="" id="Effective_Date" name="Effective_Date" tabindex="1400" />

since it would only return true or false, I was wondering if before I made any validation attempt, that I would store it as an integer instead of string...

0

"20110224" isn't a standard date string. IsDate expects something recognizable as a US date string, such as: yyyy-mm-dd. So even 2011-02-24 would work. Keep in mind the form field value's just a string. You can easily validate it and format it however you want with a few string functions.

Edited by arrgh: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.