Link to home
Start Free TrialLog in
Avatar of pcardwell
pcardwell

asked on

Building ASP Captcha into a form

We've downloaded a simple but effective ASP Captcha from http://www.betapotata.com. But we are having difficulty making it work suitably if the user incorrectly enters the captcha.

We have put this into a file, demo6.asp with form. The form should go to demo6b.asp. What we want, if captcha fails, is for the user to be immediatey returned to demo6.asp with
a) all his input except the captcha still to display in the form fields
b) the captcha image to be refreshed, showing a new image

Grateful for coding help here. Code snippet shows current incorrect coding. Separate images are not included here. Once working, we will incorporate this into a bigger form using an SQL stored procedure.
demo6.asp
<%
'Specify your captcha length here, this is the only configuration requirement
captchaLength = 5
 
Function captcha(captchaLength)
	if captchaLength > 15 then captchaLength = 15
	HighestValue = left(100000000000000,captchaLength)
	lowestValue = left(999999999999999,captchaLength)
	Randomize 
	intHighestNumber = Int((HighestValue - LowestValue + 1) * Rnd) + LowestValue
	session("captcha") = Int(intHighestNumber)
	x = 1
	response.write vbcrlf & "<table width = ''>" & vbcrlf & vbtab & "<tr>" & vbcrlf
	while x <= captchaLength
		response.write vbtab & vbtab & "<td align = 'center'><img src = 'captcha.asp?captchaID=" & x & "' ></td>" & vbcrlf
		x = x + 1
	wend
	response.write vbtab & "</tr>" & vbcrlf & "</table>" & vbcrlf
End Function
%>
 
<html> <head> 
<title>Captcha demo</title> 
</head> 
<body> 
<p><%captcha(captchaLength)%></p> 
<form action="demo6b.asp" method="post"> 
<p>Enter image characters: <input type="text" name="captcha" id="captcha" value=""></p> 
<p>Enter name:<input type="text" name="name" value=""></p> 
<p>Enter email:<input type="text" name="email" value=""></p> 
<p><input type="submit" value="submit"></p> </form>
</body>
</html>
 
demo6b.asp
<% If cstr(Request.Form("captcha")) <> cstr(Session("captcha")) Then
Response.Write "<p>Your captcha code is not valid.</p>" 
Response.Write "<p><p><a href=javascript:history.go(-1)>Try again</a></p>" 
End If 
%>
 
<html> <head> 
<title>Results</title> 
</head> 
<body> 
<p>name <%= Request.Form("name") %></p>
<p>email<%= Request.Form("email") %></p>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of R_Harrison
R_Harrison
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pcardwell
pcardwell

ASKER

Many thanks, much appreciated!