Coldfusion Contact Form Issue

Phylox
Phylox used Ask the Experts™
on
I have a contact form in CF that uses captcha code that is a bit outdated.  I want to basically make it so the error message on when the user doesn't fill a required field comes back on the same page instead of going to a server CF error message.  I have attached the two files with code in it.  
contactus.cfm.txt
contactus-confirmed.cfm.txt
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ok - the entire concept of how you are coding is geared towards going to the cf error msg

1) scratch what you are doing ...
2) learn an "ajax type" of form submitting
essentially this would entail
a) the user does not leave the form page when the form is submitted
b) if required fields are not filled in then you specify something then happens such as
the background color of the field(s) changes
a message by the field is displayed (or in the field)
etc
c) if the form is submitted properly then you can then load the next desired page

Above scenario is ideal
but to explain it to you in detail would take a sizeable chunk of time
so start studying one thing at a time

but for a quick solution read the following

1) remove the CFForm fields and use html form fields
in other words use <form action= ...> <input type= ...>

here is an example form page

<cfparam name="url.blankfields" default="">

First Name
<input type="firstname" value="">
<cfif listfindnocase(url.blankfields,"firstname")>
<b>You didn't fill in this field!!!</b>
</cfif>
<br><br>

Last Name
<input type="lastname" value="">
<cfif listfindnocase(url.blankfields,"lastname")>
<b>You didn't fill in this field!!!</b>
</cfif>
<br><br>

Email Address
<input type="email" value="">
<cfif listfindnocase(url.blankfields,"email")>
<b>You didn't fill in this field!!!</b>
</cfif>
<br><br>

et cetera et cetera ...


Then here is an example action page

<cfset blankfields="">
<cfset rList="firstname,lastname,email"><!--- this is a list of required fields --->
<cfloop list="#rList#" index="ii">
      <cfif Not StructKeyExists(form,ii) or Not len(trim(form[ii]))>
            <cfset blankfields=ListAppend(blankfields,ii)>
      </cfif>
</cfloop>

<cfif listlen(blankfields)>
      <cflocation url="formpage.cfm?blankfields=#blankfields#" addtoken="0">
      <CFABORT>
</cfif>


otherwise procede with the code ...

Author

Commented:
thx, ill give this a try and see what happens
i did forget to add that you don't want to lose valid values
so you'd need to send them also

with the first method i described that wouldn't be an issue as you don't leave the page though

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial