Do not use on any
shared computer
August 29, 2008 05:54pm pdt
 
[x]
Attachment Details

Need help with this captcha form

Tags: coldfusion 8, mozilla, localhost
I have a form that uses java for the validation and I'm trying to add captcha to it.  For some reason I'm having a very hard time with this.  I need the java validation to make sure the form is filled out correctly.  Then I need the coldfusion captcha to work also.  I posted my code below.  I'm not getting any errors but the java validation does not work and it always resets the form.

Before I tried to do captcha to this form it worked perfectly.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
<cfif isDefined("variables.memberID")>
  <cflocation url="index.cfm?newMember=1" addtoken="no">
</cfif>
<!--- Invoke the state component to get the states in a query called state. --->
<cfinvoke component="#Application.cfcRoot#.state" method="get" returnvariable="state">
<cfinvokeargument name="dsn" value="#Application.dsn#">
</cfinvoke>
<!--- Begin the layout of the membership form ... First import the javascript form library --->
<cfsetting enablecfoutputonly="no">
<script language='JavaScript' src='../_js/js_form.js'></script>
<script>
	// theForm is passed in as an object onsubmit of the form.
	// first call the appropriate functions from the library.
	// The if statement is mandatory.  The variables get defined in the library.
 
	function submitForm(theForm) {
		// validate firstName
		formRequired(theForm.firstName,'You need to enter a First Name.');
		formIsAlphaNumeric(theForm.firstName,'Please enter a valid First Name');
		
		//validate lastName
		formRequired(theForm.lastName,'You need to enter a Last Name.');
		formIsAlphaNumeric(theForm.lastName,'Please enter a valid Last Name');
		
		//validate userName
		formRequired(theForm.userName,'You need to enter a Username.');
		formIsAlphaNumeric(theForm.userName,'Please enter a valid Username');
		
		// validate password and vpassword
		formRequired(theForm.password,'You need to enter a Password.');
		formIsAlphaNumeric(theForm.password,'Please enter a valid Password.');
		formRequired(theForm.vPassword,'You need to verify your Password.');
		formIsAlphaNumeric(theForm.vPassword,'Please enter a valid verification Password.');
		if(formSubmit) {
			formIsSame(theForm.vPassword,theForm.password,'Your password and verifictation password do not match.');
		};
 
		// validate email
		formRequired(theForm.email,'You need to enter an Email Address.');
		if(formSubmit) {
			formIsEmail(theForm.email,'Please enter a valid Email Address.');
		}
				
		if(formSubmit) {
			return true;
		} else {
			formAlert();
			return false;
		}
	}
</script>
<body>
 
            <table cellspacing="0" cellpadding="0" border="0" >
              <tr>
                <td width="1" height="287" bgcolor="E0E0D6"></td>
                <td width="556" height="287" class="column_left1"><cfif isDefined("variables.message")>
                    <h3><cfoutput>#variables.message#</cfoutput></h3>
                    <cfelse>
                    <h3>Become a member</h3>
                  </cfif>
                  
                  
                  <cffunction name="makeRandomString" returnType="string" output="false">
   <cfset var chars = "23456789ABCDEFGHJKMNPQRS">
   <cfset var length = randRange(4,6)>
   <cfset var result = "">
   <cfset var i = "">
   <cfset var char = "">
   
   <cfscript>
   for(i=1; i <= length; i++) {
      char = mid(chars, randRange(1, len(chars)),1);
      result&=char;
   }
   </cfscript>
      
   <cfreturn result>
</cffunction>
 
<cfparam name="form.name" default="">
<cfparam name="form.email" default="">
<cfparam name="form.comments" default="">
<cfset showForm = true>
 
<cfif structKeyExists(form, "sendcomments")>
<cfset error = "">
<cfif hash(form.captcha) neq form.captchaHash>
<cfset error = error & "You did not enter the right text. Are you a spammer?<br />">
</cfif>
 
<cfif error is "">
<!--- If form.email isDefined we need to process the form --->
<cfscript>
	if(isDefined("form.email")) {
		member = createObject("component","#Application.cfcRoot#.member");
		security = createObject("component","#Application.cfcRoot#.security");
		if(member.isDuplicate(Application.dsn,form.username,form.email)) {
			variables.message="Either the username or email you entered already exist in the system ... Please Try Again.";
		} else {
			variables.memberID = Member.add(Application.dsn,form.email,form.firstName,form.lastName,form.businessName,form.streetAddress,form.streetAddress1,form.city,form.state,form.phone,form.postalCode);
			variables.securityID = security.addMember(Application.dsn,form.username,form.password,variables.memberid);
			security.joinRole(Application.dsn,"member",variables.securityid);
		}
	}
</cfscript>
<cfset showForm = false>
</cfif>
</cfif>
 
<cfif showForm>
<cfif structKeyExists(variables, "error")>
</cfif>
                  
                  
                  <form action="#cgi.script_name#" method="post" name="newMember">
                    <table width="567" border="0" align="center" cellpadding="0" cellspacing="3" id="formContainer">
                      <tr>
                        <td width="84" nowrap><div align="right">First Name</div></td>
                        <td width="183"><input name="firstName"<cfif isDefined("form.firstName")> value="<cfoutput>#form.firstName#</cfoutput>"</cfif> type="text" tabindex="1" title="First Name" size="25" maxlength="50"></td>
                        <td width="100" nowrap><div align="right">Last Name</div></td>
                        <td width="185"><input name="lastName" type="text" tabindex="2" title="Last Name" size="25" maxlength="50"></td>
                      </tr>
                      <tr>
                        <td height="18" nowrap><div align="right">Username</div></td>
                        <td><input name="userName" type="text" tabindex="3" title="Username" size="25" maxlength="50"></td>
                        <td nowrap><div align="right">Email</div></td>
                        <td><input name="email" type="text" tabindex="4" title="Email" size="25" maxlength="50"></td>
                      </tr>
                      <tr>
                        <td nowrap><div align="right">Password</div></td>
                        <td><input name="password" type="password" tabindex="5" title="Password" size="25" maxlength="15"></td>
                        <td nowrap><div align="right">Verify Password</div></td>
                        <td><input name="vPassword" type="password" tabindex="6" title="Verify Password" size="25" maxlength="15"></td>
                      </tr>
                      <tr>
                        <td nowrap><div align="right">Business Name</div></td>
                        <td colspan="3"><input name="businessName" type="text" id="businessName" tabindex="7" title="Business Name" size="73" maxlength="100" /></td>
                      </tr>
                      <tr>
                        <td nowrap><div align="right">Business Address</div></td>
                        <td colspan="3"><input name="streetAddress" type="text" tabindex="8" title="Street Address" size="73" maxlength="100"></td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td colspan="3"><input name="streetAddress1" type="text" tabindex="9" title="Street Address" size="73" maxlength="100"></td>
                      </tr>
                      <tr>
                        <td height="24" nowrap><div align="right">City</div></td>
                        <td><input name="city" type="text" tabindex="10" title="City" size="25" maxlength="50"></td>
                        <td nowrap><div align="right">State/Province </div></td>
                        <td><SELECT NAME="state" size="1" id="state" style="width:150;" tabindex="11" title="State/Province">
                            <OPTION VALUE="0" selected> Select State/Province </OPTION>
                            <cfoutput query="state">
                              <OPTION VALUE="#state.ID#"> #state.name# </OPTION>
                              #chr(10)#</cfoutput>
                          </SELECT>                        </td>
                      </tr>
                      <tr>
                        <td nowrap><div align="right">Telephone: </div></td>
                        <td><label>
                          <input name="phone" type="text" id="phone" size="25" tabindex="12"/>
                          </label></td>
                        <td nowrap class="small"><div align="right">Postal Code</div></td>
                        <td class="small"><input name="postalCode" type="text" tabindex="13" title="Postal Code" size="25" maxlength="50"></td>
                      </tr>
                      <tr>
                        <td colspan="4"><div align="center">
                          Enter text below: 
                          <input type="text" name="captcha" />
                          <cfset captcha = makeRandomString()>
    					  <cfset captchaHash = hash(captcha)>
                          <input type="hidden" name="captchaHash" value="#captchaHash#">
                        </div></td>
                      </tr>
                      <tr>
                        <td colspan="4"><div align="center"><cfimage action="captcha" width="300" height="75" text="#captcha#" fonts="verdana,arial"></div></td>
                      </tr>
                      <tr>
                        <td colspan="4">&nbsp;</td>
                      </tr>
                      <tr>
                        <td colspan="4"><div align="center">
                            <input name="Submit" type="submit" value="Join">
                            By clicking this button you agree to our<a href="../../terms_of_use.cfm"> terms of service</a></div></td>
                      </tr>
                    </table>
                  </form>
                  </cfif>
                </td>
                <td width="1" height="287" bgcolor="E0E0D6"></td>
              </tr>
            </table>
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Web Development
Question Asked By: sonicimpulse
Solution Provided By: hielo
Participating Experts: 1
Solution Grade: A
Views: 0
Translate:
Loading Advertisement...
 
[+][-]Accepted Solution by hielo

Rank: Genius

Accepted Solution by hielo:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628