It's a very good method, Les... although I can't take credit for it.
It was passed on to me a long time ago. No client-side validation at all.
Here's a code sample involving two form fields, First_Name & Last_Name.
The page, Name_Form.cfm contains the validation code, error messages
display,
form and inputs.
Page: Name_Form.cfm
<HTML>
<HEAD>
</HEAD>
<BODY>
<!--- Section 1 / Creates Struct to hold form errors and clears the struct
every time the page is refreshed --->
<CFSET Form_Errors = StructNew()> <!--- Create the Struct, "Form_Errors", to
hold error messages if they are created during validation --->
<CFSET Temp = StructClear(Form_Errors)> <!--- Clears the Struct,
"Form_Errors", each time the form is submitted so no error messages exist
--->
<!--- Section 2 / Checks to make sure form has been submitted back to this
page and, if so, runs validation on form data --->
<CFIF IsDefined("Form.First_Name")> <!--- This makes sure that the form has
been submitted. If it hasn't the validation code won't be run. --->
<CFIF Not Len(Trim(Form.First_Name))> <!--- Checks to see if the
First_Name field is empty --->
<CFSET Form_Errors.First_Name = "Please enter your first name.">
<!--- Creates error message for First_Name field --->
</CFIF>
<CFIF Not Len(Trim(Form.Last_Name))> <!--- Checks to see if the
Last_Name field is empty --->
<CFSET Form_Errors.Last_Name = "Please enter your last Name.">
<!--- Creates error message for Last_Name field --->
</CFIF>
</CFIF>
<!--- Section 3 / Checks to make sure form has been submitted and, if so,
then checks to make sure there are no error messages in the struct
and, if not, proceeds with data processing. After
data processing, sends user to success page. --->
<CFIF IsDefined("Form.First_Name")> <!---Again, this checks to see if the
form has been submitted. If not "Form.First_Name won't exist. --->
<CFIF StructIsEmpty(Form_Errors)> <!--- Checks to see if the Struct hold the
form errors is empty. If it is, there were no errors. --->
<!--- Since the form has been submitted and there are no errors in the
data, processing takes place here... sending email, queries, etc. --->
<CFLOCATION URL = "Form_Submission_Success.cfm" AddToken="No"> <!---
Once the data from the form is processed, the user is sent to a success
page. --->
</CFIF>
</CFIF>
<!--- Section 4 / Displays notice of errors in form, error messages, field
names, and form inputs --->
<CFIF Not StructIsEmpty(Form_Errors)> <!--- Checks to see if Struct does
contain error messages --->
"I'm sorry, but there are problems with your required entries. Please
check your entries, make necessary corrections, and re-submit."
<!--- The message above is sent to the user to let them know there are
form errors. I put this message above the form, since some of the errors
may be below the visual area on the screen. --->
</CFIF>
<!---- This next section outputs any form_error struct messages above the
form name and input field --->
<CFIF IsDefined("Form_Errors.First_Name") and
Len(Trim(Form_Errors.First_Name))> <!--- Makes sure struct key exists and
the error message has length. --->
<FORM Name="Form_Validation" Action="Name_Form.cfm" Method="Post">
<TABLE>
<TR>
<TD>
<CFOUTPUT>#Form_Errors.First_Name#</CFOUTPUT>
</TD>
</TR>
</CFIF>
<TR>
<TD>
First Name (required)
</TD>
</TR>
<TR>
<TD>
<CFIF IsDefined("Form.First_Name")>
<INPUT Name="First_Name" Type="Text"
Value="<CFOUTPUT>#Form.First_Name#</CFOUTPUT>" Size="40">
<CFELSE>
<INPUT Name="First_Name" Type="Text" Value="" Size="40">
</CFIF>
</TD>
</TR>
<CFIF IsDefined("Form_Errors.Last_Name") and
Len(Trim(Form_Errors.Last_Name))> <!--- Makes sure struct key exists and the
error message has length. --->
<TR>
<TD>
<CFOUTPUT>#Form_Errors.First_Name#</CFOUTPUT>
</TD>
</TR>
<TR>
<TD>
Last Name (required)
</TD>
</TR>
<TR>
<TD>
<CFIF IsDefined("Form.Last_Name")>
<INPUT Name="Last_Name" Type="Text"
Value="<CFOUTPUT>#Form.Last_Name#</CFOUTPUT>" Size="40">
<CFELSE>
<INPUT Name="Last_Name" Type="Text" Value="" Size="40">
</CFIF>
</TD>
</TR>
<TR>
<TD>
<INPUT Type="Submit" Name="Name_Form_Submit" Value="Submit">
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
Page: Form_Submission_Success.cfm
<HTML>
<HEAD>
</HEAD>
<BODY>
The Name Form has been successfully submitted!
</BODY>
</HTML>
And that's a basic layout of the code...
I've attached the two pages involved. You can run them on a server and
study them
or you can view them at work at
http://bodaford.whitestonemedia.com/html/Name_Form.cfm
Let me know if this helps or what doesn't make sense...
Rick
-----Original Message-----
From: Les Mizzell [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 18, 2007 5:48 PM
To: CF-Talk
Subject: Re: Client-side validation or Server-side Validation?
What you're doing below sounds exactly like what I need for some
specific forms that seem to have lot of business users with no JS. I
haven't completely wrapped my head around what you're doing though.
Is there a good reference for your method somewhere on the web I can
study, or do you mind going a little deeper into detail?
Thanks, LGM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Macromedia ColdFusion MX7
Upgrade to MX7 & experience time-saving features, more productivity.
http://www.adobe.com/products/coldfusion?sdid=RVJW
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:275821
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4