Well... you
could pretty easily append all the form variables to your URL line in the CFLOCATION:
Code:
<CFIF Checkusername.RecordCount GT 0>
<CFSET myQueryStr = "">
<CFLOOP index="whichFormField" list="#FORM.FieldNames#">
<CFIF CompareNoCase(whichFormField,"username") NEQ 0>
<CFSET myQueryStr = myQueryStr & "&" & whichFormField & "=" & URLEncodedFormat(FORM[whichFormField])>
</CFIF>
</CFLOOP>
<CFLOCATION URL="RegistForm1.cfm?Message=#URLEncodedFormat("The
username you chose already exists, please choose a different
username.")#&FullName=#URLEncodedFormat(FullName)##myQueryStr#">
</CFIF>
But... with a complex form (or even with a simple form), you're likely to overrun the limit to the amount of characters that are supposed to be in a URL (which I believe is 255).
Let me turn you around a little bit. Your solution is the reverse of what I've always implemented. Instead of the form submitting to an different action page, have it submit to itself... then either do a CFLOCATION to a thank you page or CFINCLUDE the thank you page at the top (if you need access to the form variables).
Try copying and pasting the following simple example:
form.cfm-
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>Form Submission</title>
</head>
<body>
<CFPARAM name="FORM.firstname" default="">
<CFPARAM name="FORM.lastname" default="">
<CFPARAM name="FORM.zipcode" default="">
<CFIF IsDefined("form.submit") AND CompareNoCase(form.submit,"Go") EQ 0>
<CFIF Len(Trim(FORM.firstname)) GT 0 AND Len(Trim(FORM.lastname)) GT 0>
<CFINCLUDE template="thankyou.cfm">
<CFABORT>
<CFELSE>
<p>There was an error in your form.<br />
Kindly fill in all the required fields.</p>
</CFIF>
</CFIF>
<p> </p>
* = required fields<br />
<CFOUTPUT>
<form action="#GetFileFromPath(GetBaseTemplatePath())#" method="post">
First name *: <input type="text" name="firstname" value="#FORM.firstname#" /><br />
Last name *: <input type="text" name="lastname" value="#FORM.lastname#" /><br />
Zip code (optional): <input type="text" name="zipcode" value="#FORM.zipcode#" /><br />
<input type="submit" name="submit" value="Go" />
</form>
</CFOUTPUT>
</body>
</html>
and
thankyou.cfm-
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>Form Thank You</title>
</head>
<body>
<CFOUTPUT>Thank you, #FORM.firstname# #FORM.lastname# for filling out our form correctly!</CFOUTPUT>
</body>
</html>
What the form.cfm page does is set up a form to submit to itself (#GetFileFromPath(GetBaseTemplatePath())# is a fancy way to get the present filename... so if you ever happen to rename or copy your form page, you'll always be submitting to the right place without having to touch the code).
When the form is submitting (to itself), the top of the form.cfm page recognizes that it's been submitted, checks that all the required fields are filled in, then includes the thank you page and aborts the redisplay of the form. If all the fields
aren't filled in, it simply doesn't include the thank you page, doesn't abort, and falls out to redisplay the form again (with the submitted data already filled in).
It's a very handy method to use... and tends to be much easier to maintain than passing variables back on the URL or whatnot.
-Carl