Advertisement

06.06.2008 at 06:50AM PDT, ID: 23463664
[x]
Attachment Details

Need help adding a query to this form with captcha

Asked by sonicimpulse in Cold Fusion Markup Language, Web Languages/Standards

Tags: coldfusion 8, mozilla, localhost

I have a form here with captcha java script.  I'm not sure how and where if they enter the correct set of letters that it will process the query.  I posted all the code below.

I'm using coldfusion 8Start Free Trial
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:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
<script language='JavaScript'>
 window.onload=init;
 
 function init()
 {
 	var val = code()
 	document.getElementById('hiddenCaptcha').value=val;
 	document.getElementById('visibleCaptcha').innerHTML=val;
 }
 function Random(X) {
    return Math.floor(X * (Math.random() % 1));
}
 function code() {
    var j, S = ""; 
    for (j = 0; j < 3; j++) {
        S += String.fromCharCode(65 + Random(26));
        S += String.fromCharCode(97 + Random(26));
    }
    return S;
}
 
 
// Declare Global Variables
 
	var formAlertMessage='There were Errors!';
	var formSubmit=1;
 
/*
	throwError gets called each time there is an error in the
	validation routines.
*/
function throwError (theField,theMessage) {
	formAlertMessage=formAlertMessage + "\n - " + theMessage;
	formSubmit=0;
	switchStyle(theField);
}
function switchStyle (theField) {
	theSwitch=new Function("this.style.backgroundColor='FFFFFF';this.style.color='000000';if(this.type=='text') this.select();")
	theField.style.backgroundColor='FF0000';
	theField.style.color='White';
	theField.onfocus=theSwitch;
}
 
/*
	formAlert displays the alert message and clears necessary variables to start
	the validation over.
*/
 
function formAlert() {
	alert(formAlertMessage);
	formAlertMessage='There were Errors!';
	formSubmit=1;
}
 
 
/*
	formRequired makes sure a field has been completed by the user.   In order
	for this function to work with select boxes the empty value must be set to 0
	in the form.
*/
 
function formRequired(theField,theMessage) {
	theField.value = theField.value.replace(/\s+$|^\s*/gi, "");
	if(theField.value == '' || theField.value == '-1' || theField.value == '0') {
		throwError(theField,theMessage);
	}
}
 
// form field must be composed only of numbers and letters.
function formIsAlphaNumeric(theField,theMessage) {
	theField.value = theField.value.replace(/\s+$|^\s*/gi, "");
	isAlphaNum = new RegExp ("[^0-9a-zA-Z \(\)\-\.\/]");
	if (isAlphaNum.test(theField.value)) {
		throwError(theField,theMessage);
	}
}
 
// form field must be composed only of numbers and letters.
function formIsSame(field1,field2,theMessage) {
 
	if(field1.value != field2.value) {
		throwError(field2,theMessage);
		switchStyle(field1);
	}
}
 
function formIsEmail (theField,theMessage) {
	var email = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
 	if(!email.test(theField.value)) {
		throwError(theField,theMessage);
	}
 }
</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.');
		formRequired(theForm.userCaptcha,'Please enter sign up code.');
 
		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)
		{
			if( theForm.userCaptcha.value !== theForm.hiddenCaptcha.value )
			{
				formSubmit=false;
				throwError(theForm.userCaptcha,'Signup Code is incorrect');
				//generate a new captcha code
				init();
			}
		}
 
		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">
        <h3>Become a member</h3>
      
      <form action="" method="post" name="newMember" onSubmit="return submitForm(this)">
        <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" 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>
                
                  <OPTION VALUE="OH"> Ohio </OPTION>
                  
 
              </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="2">Signup Code: <span style="font-weight:bold;color:navy;background-color:#ededed;" id="visibleCaptcha"></span></td>
		</tr>
		<tr>
			<td colspan="2">Enter Signup Code: <input type="text" name="userCaptcha" id="userCaptcha" value=""/></td>
		</tr>
          <tr>
            <td colspan="4"><div align="center"><input type="hidden" name="hiddenCaptcha" id="hiddenCaptcha" value=""/>
                <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></td>
    <td width="1" height="287" bgcolor="E0E0D6"></td>
  </tr>
</table>
</td>
</tr>
</table>
[+][-]06.06.2008 at 12:33PM PDT, ID: 21732058

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.06.2008 at 07:43PM PDT, ID: 21733983

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.06.2008 at 07:58PM PDT, ID: 21734016

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Cold Fusion Markup Language, Web Languages/Standards
Tags: coldfusion 8, mozilla, localhost
Sign Up Now!
Solution Provided By: gdemaria
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628