The trick is defaulting all of your form values and then always giving
your input a value="" attribute.
Very quick example:
<!--- Form defaults --->
<cfparam name="form.name" default="">
<!--- Form validation --->
<cfset errors = arrayNew(1) />
<cfif not len(trim(form.name))>
<cfset arrayAppend(errors, "Please enter your name.") />
</cfif>
<!--- Show Errors --->
<cfif arrayLen(errors)>
<p>Please correct the following errors:</p>
<ul>
<cfoutput>
<cfloop from="1" to="#arrayLen(errors)#" index="i">
<li>#errors[i]#</li>
</cfloop>
</ul>
</cfif>
<!--- Show Form --->
<cfform name="myForm" action=""> <cfinput type="text" name="name" value="#form.name#" required="yes"
message="Please enter your name." />
<input type="submit" name="submit" value="Submit" />
</cfform>
----- Original Message -----
From: Roberto Perez <[EMAIL PROTECTED]>
Date: Mon, 16 Aug 2004 02:30:03 -0400
Subject: keeping form data during server-side validation
To: CF-Talk <[EMAIL PROTECTED]>
Hi all,
Maybe this topic has been covered before, but I'm not sure what keywords
I'd use in Google or in the list archives to find related messages.
I want to validate data from a form (missing fields, password field and
re-enter password field, etc.), and reload the form page with an error
message. However, when I do this I lose all data entered, and the user has
to reenter everything again. If I display an empty page with a message like
"use the back button to go back to the form and correct the information",
by using the back button in the browsers users do get the fields populated.
Do you have specific instructions/steps to get that effect (going back to
pre-populated fields) using CF (instead of using the back button in the
browser)?
Another option would be to do the validation client-side with _javascript_,
but I'd rather do it server side on the browser.
Thanks,
Roberto Perez
[EMAIL PROTECTED]
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

