Link to home
Start Free TrialLog in
Avatar of Quack
QuackFlag for United States of America

asked on

I have an issue with a date field in a Cold Fusion form not working with server side validation...

I have an invoice form that needs a date field to be formatted with mm/dd/yy . Its currently working on the client side fine but on the server side I have issues with javascript turned off which is the whole reason I'm formatting it this way. The security requirement is for server  side to catch issues if someone is trying to hack the form w/ javascript turned off in firefox.

Here's the code I have for the parameters:
<cfparam name="form.Invoice_Date" default="">

<cfif session.invoiceDataContr.fileError NEQ 2>
<cfset session.invoiceDataContr.Invoice_Date = "#form.Invoice_Date#">
<cfparam name="form.Invoice_Date" default="">

<cfelse>
<cfset session.invoiceDataContr.Invoice_Date = "#session.invoiceDataContr.Invoice_Date#">

Open in new window


form field:
	<cfset myDate = "#form.Invoice_Date#">
<cfset myYear = #DatePart("yyyy", todayDate)#>
	<cfif isValid("usdate", form.Invoice_Date)>
	     <cfset r_myDate = "20#right(form.Invoice_Date, len(form.Invoice_Date)- 6)#">	
		 <cfif r_myDate GT myYear> 
			<cfset #session.invoiceDataContr.errorString# =#session.invoiceDataContr.errorString#&" No future dates are allowed. Enter date in MM/DD/YY format.,">
	     <cfelse>			  
			<cfif datecompare(todayDate, myDate, "d") EQ -1> 
				<cfset #session.invoiceDataContr.errorString# =#session.invoiceDataContr.errorString#&" No future dates are allowed. Enter date in MM/DD/YY format.,">
			</cfif>			 
		</cfif>       
	<cfelse>
		<cfset #session.invoiceDataContr.errorString# =#session.invoiceDataContr.errorString#&" The Invoice Date is required. No future dates are allowed. Enter date in MM/DD/YY format.,">
	</cfif>	

Open in new window


hidden field:
<input type="hidden" name="Invoice_Date" id="Invoice_Date" value="#HTMLEditFormat(session.invoiceDataContr.Invoice_Date)#">

Open in new window


Its giving me an internal server error when I put the date in as: 4/2/17.

The cf application error log is returning:

The 2 parameter of the Right function, which is now 0, must be a positive integer The specific sequence of files included or processed is: D:\inetpub\wwwroot\**********\**********_verify.cfm, line: 127

It's working for most everything else but this isn't being caught. Before its suggested to use mm/dd/yyyy I can't do that. Specific requirement which is really screwing things up or this wouldn't be an issue likely.

Thanks for any suggestions.
Avatar of gdemaria
gdemaria
Flag of United States of America image

Not sure where in the code it is failing, but it should not matter how the user enters the date.  The first thing you do is validate the date and the second thing you do should be to convert the date to the format you want to use to support your code.   mm/dd/yyyy  ... or whatever it is.   What the user seems and the format you work with can be different.   Just format the date to the required display format when writing it to the screen, at all other times, ensure you have a full, valid date in the format you need.
Avatar of Quack

ASKER

Isn't the date already being validated w/ the current code?
ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Quack

ASKER

thanks for the help...I'm trying to talk them into a different format