troubleshooting Question

How to resolve the CAPTCHA script inside my ASP form?

Avatar of Stiebel Eltron
Stiebel EltronFlag for Thailand asked on
ASPWeb DevelopmentJavaScript
23 Comments1 Solution1029 ViewsLast Modified:
Dear EE Experts,

Please see the attached codes that we have, kindly check & advise why does the CAPTCHA script isn't working, what I mean is if a user type it wrong, it will still send the form, it's not checking the spelling...

Please advise...
<%@LANGUAGE="VBSCRIPT"%>
<%
function TestCaptcha(byval valSession, byval valCaptcha)
	dim tmpSession
	valSession = Trim(valSession)
	valCaptcha = Trim(valCaptcha)
	if (valSession = vbNullString) or (valCaptcha = vbNullString) then
		TestCaptcha = false
	else
		tmpSession = valSession
		valSession = Trim(Session(valSession))
		Session(tmpSession) = vbNullString
		if valSession = vbNullString then
			TestCaptcha = false
		else
			valCaptcha = Replace(valCaptcha,"i","I")
			if StrComp(valSession,valCaptcha,1) = 0 then
				TestCaptcha = true
			else
				TestCaptcha = false
			end if
		end if		
	end if
end function
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head>


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">

<meta name="GENERATOR" content="Mozilla/4.7 [en] (Win98; I) [Netscape]">

<title>..:: Stiebel ::..</title>
<style TYPE="text/css">
<!--
	a
 	{
  		color:#000080;
		font-family:verdana;
		text-decoration:none;
		font-size:12px
	}
	
	
	a:active
 	{
  		color:red;

	}

	a:hover
 	{
  		color:#FF0000;
		text-decoration:none;
		cursor:crosshair;
	}
		
	table
	{
		font-family:verdana;
	}
	
	.td
	{
		font-family:verdana;
		font-size:12px;
	}

	.b
	{
		font-color:#FF0000;
		font-family:verdana;
		font-size:12px;
	}		

-->
</STYLE>

<!--validation-->

<script language="JavaScript" type="text/javascript">
if(!String.prototype.trim) {
  String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/, '');
  };
}

function isEmail(string) {
  return (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
}
function checkform ( form ) {
  // ** START **
  if (form.username.value.trim() == "") {
    alert( "Please enter your Username." );
    form.username.focus();
    return false ;
  }
  if (form.password.value.trim() == "") {
    alert( "Please enter your Password." );
    form.password.focus();
    return false ;
  }
  if (form.repassword.value.trim() == "") {
    alert( "Please retype your Password." );
    form.repassword.focus();
    return false ;
  }
  if (form.repassword.value.trim() != form.password.value.trim()) {
    alert( "Password didn't match. Please retype." );
    form.repassword.focus();
    return false ;
  }
  if (form.fname.value.trim() == "") {
    alert( "Please enter your name." );
    form.fname.focus();
    return false ;
  }
  if (form.lname.value.trim() == "") {
    alert( "Please enter your surname." );
    form.lname.focus();
    return false ;
  }
  if (form.company.value.trim() == "") {
    alert( "Please enter your company name." );
    form.company.focus();
    return false ;
  }
  if (form.address.value.trim() == "") {
    alert( "Please enter your address." );
    form.address.focus();
    return false ;
  }
  if (form.email.value.trim() == "") {
    alert( "Please enter your email address." );
    form.email.focus();
    return false ;
  }
  
  if (!isEmail(form.email.value.trim())) {
    alert("Please enter correct Email address");
	  form.email.focus();
	  return false;
  }

  if (form.telephone.value.trim() == "") {
    alert( "Please enter your Telephone#." );
    form.telephone.focus();
    return false ;
  }
  if (form.mobile.value.trim() == "") {
    alert( "Please enter your Mobile#." );
    form.mobile.focus();
    return false ;
  }
  if (form.code.value.trim() == "") {
    alert( "Please retype the confirmation code." );
    form.code.focus();
    return false ;
  }
//  if (form.remobile.value.trim() != form.mobile.value.trim()) {
//    alert( "Mobile didn't match. Please retype." );
//    form.remobile.focus();
//    return false ;
//  }
  
    // ** END **
    return true ; // allow submission
}
</script>
<!-- captcha image-->
<script language="javascript">
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}
</script>
<!--END-->

</head>

<body bgproperties="fixed" bgcolor="#000000" onLoad="javascript:startmenu()">

<table width="760" border="0" cellspacing="3" cellpadding="1">
  <tr>
    <td width="134"><img src="../IMG/logo_res.jpg" alt="STIEBEL ELTRON" /></td>
    <td width="620" valign="top" bgcolor="#666666"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="548" height="197">
      <param name="movie" value="homeintro20.swf" />
      <param name="quality" value="high" />
      <param name="wmode" value="opaque" />
      <embed src="homeintro20.swf" quality="high" wmode="opaque" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="548" height="197"></embed>
    </object></td>
    <td width="134" bgcolor="#FFFFFF"><img src="../IMG/white_square.png" alt="ASIA" border="0" align="top"/></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="right" bgcolor="#999999"><font face="Verdana, Geneva, sans-serif" color="#ffffff">
    <%
   '// If user is logged in show name and logout link
   If Session("loggedin") = true Then
      Response.Write "Welcome: " & Session("name")
      Response.Write "<br /><a href=""../asia/login2/logout.asp"">Logout</a>"
   Else
      Response.Write "<a href=""ste-iphoto-login.asp"" title=""CLICK TO LOGIN"">REGISTERED USERS</a>"
   End If
	%>&nbsp;
	</td>
    <td bgcolor="#666666" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="left" bordercolor="#999999" bgcolor="#000000"><img src="../IMG/member.jpg" width="548" /><br></td>
    <td bgcolor="#999999" valign="top" align="center" rowspan=13>&nbsp;
		
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
    	<table width="100%" border="1" bordercolor="#ffffff" cellpadding="0" bgcolor="#999999">
    		<form name="form" id="form" method="post" action="signup_result.asp" onSubmit="return checkform(this)">

    		<tr>
        		<td class="td" width="20%" align="right">First Name:</td>
           		<td width="80%"><input id="fname" name="fname" type="text" size="50" maxlength="50" />&nbsp;<b><font class="b">*</font>
                </b>
                </td>
        	</tr>
    		<tr>
        		<td class="td" width="20%" align="right">Last Name:</td>
           		<td width="80%"><input id="lname" name="lname" type="text" size="50" maxlength="50" />&nbsp;<b><font class="b">*</font>
                </b>
                </td>
        	</tr>
           	<tr>
        		<td class="td" width="20%" align="right">Email:</td>
           		<td width="80%"><input id="email" name="email" type="text" size="50" maxlength="50" />&nbsp;<b><font class="b">*</font></b>	
            	</td>
        	</tr>

<!--            
	    	<tr>
    	    	<td class="td" width="20%" align="right">Username:</td>
	    	   	<td width="80%"><input id="username" name="username" type="text" size="25" maxlength="15" onkeyup="OnChangedUsername" />&nbsp;<b><font class="b">*</font></b>&nbsp;<input id="btnCheckAvailability" type="button" disabled="disabled" value="Check Availability" onclick="OnCheckAvailability();" />&nbsp;&nbsp;<div id="Available"></div>
                </td>
        	</tr>
-->            
    		<tr>
        		<td class="td" width="20%" align="right">Password:</td>
           		<td width="80%"><input id="password" name="password" type="password" size="25" maxlength="15" />&nbsp;<b><font class=
                "b">*</font></b>
                </td>
        	</tr>
    		<tr>
        		<td class="td" width="20%" align="right">Re-type Password:</td>
           		<td width="80%"><input id="repassword" name="repassword" type="password" size="25" maxlength="15" />&nbsp;<b><font class="b">*</font></b>
                </td>
        	</tr>
        	<tr>
        		<td class="td" width="20%" align="right">Country:</td>
           		<td width="80%"><input id="country" name="country" type="text" size="50" maxlength="50" />&nbsp;<b><font class="b">*</font></b>	
         	   </td>
        	</tr>
	        <tr>
    	    	<td class="td" width="20%" align="right">Telephone:</td>
        	   	<td width="80%"><input id="telephone" name="telephone" type="text" size="25" maxlength="15" />&nbsp;<b><font class="b">
                *</font></b>
                </td>
        	</tr>
        	<tr>
        		<td class="td" width="20%" align="right">Mobile:</td>
           		<td width="80%"><input id="mobile" name="mobile" type="text" size="25" maxlength="15" />&nbsp;<b><font class="b">*
                </font></b>
                </td>
        	</tr>
	    	<tr>
    	    	<td class="td" width="20%" align="right">Company:</td>
        	   	<td width="80%"><input id="company" name="company" type="text" size="50" maxlength="25" />&nbsp;<b><font class="b">*
                </font></b>
                </td>
        	</tr>
    		<tr valign="top">
        		<td class="td" width="20%" align="right">Address:</td>
           		<td width="80%"><textarea name="address" id="address" rows="4" cols="39"></textarea>&nbsp;<b><font class="b">*</font>
                </b>
                </td>
        	</tr>
	        <tr>
    	    	<td class="td" width="20%" align="right">Confirm code:&nbsp;
				</td> 
           		<td width="80%">
            		<img id="imgCaptcha" src="captcha.asp" /><br />
                    <a href="javascript:void(0)" onclick="RefreshImage('imgCaptcha')">Change Image</a><br />
		            <input id="code" name="code" type="text" size="25" maxlength="15" />&nbsp;<b><font class="b">*</font></b>
                </td>
        	</tr>
	        <tr>
        		<td class="td" width="20%" align="right">&nbsp;</td>
           		<td width="80%"><input name="Submit" type="submit" value="SUBMIT FORM" onclick="checkform();" />&nbsp;
            		<input name="Reset" type="reset" value="RESET FORM" onClick="return confirm('Are you sure you want to reset the 
                    form?')" />
                </td>
        	</tr>
			<%
			if not IsEmpty(Request.Form("Submit")) then
			Response.Write("<tr><td colspan=""2"" align=""center"">")
			if TestCaptcha("ASPCAPTCHA", Request.Form("captchacode")) then
			Response.Write("<b style=""color:#00CC33"">The code you enter verified.</b>")
			else
			Response.Write("<b style=""color:#FF0000"">You entered the wrong code.</b>")
			end if
			Response.Write("</td></tr>" & vbCrLf)
			end if
			%>


        </form>
        
        <!--javascript-->
        <script language="JavaScript" type="text/javascript">
		//If our user enters data in the username input, then we need to enable our button
		function OnChangedUsername()
		{
		if(document.form.username.value == "")
		{
		document.form.btnCheckAvailability.disabled = true;
		}
		else
		{
		document.form.btnCheckAvailability.disabled = false;
		}
		}
		function OnCheckAvailability()
		{
		if(window.XMLHttpRequest)
		{
		oRequest = new XMLHttpRequest();
		}
		else if(window.ActiveXObject)
		{
		oRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}

		oRequest.open("POST", "AJAX.asp", true);
		oRequest.onreadystatechange = UpdateCheckAvailability;
		oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oRequest.send("strCmd=availability&strUsername=" + document.form.username.value);
		}
		function UpdateCheckAvailability()
		{
		if(oRequest.readyState == 4)
		{ 
		if(oRequest.status == 200)
		{
		document.getElementById("Available").innerHTML = oRequest.responseText;
		}
		else
		{
		document.getElementById("Available").innerHTML = "Asychronous Error";
		}
		}
		}
		</script>
        <!--END-->
    </table>
    </td>
  </tr>
   <tr>
    <td>&nbsp;</td>
    <td align="center" bgcolor="#ffffff">
    	<a href = "javascript:history.back()"><font size="0.5e">BACK</font></a>
    </td>
  </tr>
</table>

</body>
</html>
ASKER CERTIFIED SOLUTION
Wayne Barron
Author, Web Developer
Join our community to see this answer!
Unlock 1 Answer and 23 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 23 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros