The problem is: When click on the Send Mail the button does the
validation of the form BUT not the validation of the data input in the
reCAPTCHA
Please help
On Oct 7, 7:23 pm, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
> Please seehttp://groups.google.com/group/recaptcha/browse_thread/thread/91d9a1e...
>
> On 10/7/07, Apostolos <i...@easytraveller.gr> wrote:
>
>
>
> > I have the site easytraveller.gr which is using several asp forms.
> > How can I use the reCAPTCHA in these forms to avoid the hundreds of
> > spam emails?
>
> --
> reCAPTCHA: stop spam, read bookshttp://recaptcha.net
On Oct 8, 11:06 pm, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
> reCAPTCHA needs to be validated on the server, not the client.
>
> On 10/8/07, Apostolos <i...@easytraveller.gr> wrote:
>
>
>
>
>
> > Thank you up to now
> > I have come almost to the end
> > You can see my test form athttp://www.easytraveller.gr/contactNEW.asp
On Oct 8, 2:06 pm, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
> reCAPTCHA needs to be validated on the server, not the client.
>
> On 10/8/07, Apostolos <i...@easytraveller.gr> wrote:
>
>
>
>
>
> > Thank you up to now
> > I have come almost to the end
> > You can see my test form athttp://www.easytraveller.gr/contactNEW.asp
<script type="text/javascript" src="http://api.recaptcha.net/
challenge?k=<...>">
</script>
<noscript>
<iframe src="http://api.recaptcha.net/noscript?
k=<...>"
frameborder="0">
</iframe><br>
<textarea name="recaptcha_challenge_field" rows="3"
cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field"
value="manual_challenge">
</noscript>
<%
' Test the captcha field
Dim IsGoodCaptcha
IsGoodCaptcha = false
Dim privateKey
privateKey = "<...>"
Dim VarString
VarString = _
"privatekey=" & privateKey & _
"&remoteip=" & Request.ServerVariables("REMOTE_ADDR")
& _
"&challenge=" &
Request.Form("recaptcha_challenge_field") & _
"&response=" &
Request.Form("recaptcha_response_field")
Dim objXmlHttp
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "POST", "http://api-verify.recaptcha.net/
verify"
objXmlHttp.setRequestHeader "Content-Type", "application/
http://www.easytraveller.gr/contactNEW.asp"
objXmlHttp.send VarString
Dim ResponseString
ResponseString = split(objXmlHttp.responseText, vblf)
Set objXmlHttp = Nothing
if ResponseString(0) = "true" then
'They answered correctly - do something
IsGoodCaptcha = true
else
'They answered incorrectly
IsGoodCaptcha = false
ErrorCode = "&error=" & ResponseString(1)
end if
%>
<input name="Button" type="submit" value="Send Mail"
onclick="validate();return returnVal;" >
Would very much appreciate any correction neede
On Oct 8, 11:06 pm, "reCAPTCHA Support" <supp...@recaptcha.net> wrote:
> reCAPTCHA needs to be validated on the server, not the client.
>
> On 10/8/07, Apostolos <i...@easytraveller.gr> wrote:
>
>
>
>
>
> > Thank you up to now
> > I have come almost to the end
> > You can see my test form athttp://www.easytraveller.gr/contactNEW.asp
Feel free to clean these up and improve them and bundle them up so
next person can have an easier time
Mark
<%
' returns string the can be written where you would like the reCAPTCHA
challenged placed on your page
function recaptcha_challenge_writer(publickey)
recaptcha_challenge_writer = "<script type=""text/javascript"">" & _
"var RecaptchaOptions = {" & _
" theme : 'white'," & _
" tabindex : 0" & _
"};" & _
"</script>" & _
"<script type=""text/javascript"" src=""http://api.recaptcha.net/
challenge?k=" & publickey & """></script>" & _
"<noscript>" & _
"<iframe src=""http://api.recaptcha.net/noscript?k=" & publickey &
""" frameborder=""1""></iframe><br>" & _
"<textarea name=""recaptcha_challenge_field"" rows=""3""
cols=""40""></textarea>" & _
"<input type=""hidden"" name=""recaptcha_response_field""
value=""manual_challenge"">" & _
"</noscript>"
end function
function recaptcha_confirm(privkey,rechallenge,reresponse)
' Test the captcha field
Dim VarString
VarString = _
"privatekey=" & privkey & _
"&remoteip=" & Request.ServerVariables("REMOTE_ADDR") & _
"&challenge=" & rechallenge & _
"&response=" & reresponse
Dim objXmlHttp
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "POST", "http://api-verify.recaptcha.net/verify",
False
objXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-
urlencoded"
objXmlHttp.send VarString
Dim ResponseString
ResponseString = split(objXmlHttp.responseText, vblf)
Set objXmlHttp = Nothing
if ResponseString(0) = "true" then
'They answered correctly
recaptcha_confirm = ""
else
'They answered incorrectly
recaptcha_confirm = ResponseString(1)
end if
end function
%>
Here is the code I use:
<form id="captcha" name="captcha" method="post"
action="contactNEW.asp">
<script type="text/javascript"
src="http://api.recaptcha.net/challenge?k=public key">
</script>
<noscript>
<iframe
src="http://api.recaptcha.net/noscript?
k=public key">
height="300"
width="500"
frameborder="0">
</iframe><br>
<textarea name="recaptcha_challenge_field" rows="3"
cols="40"></
textarea>
<input type="hidden" name="recaptcha_response_field"
value="manual_challenge">
</noscript>
<%
' Test the captcha field
Dim IsGoodCaptcha
IsGoodCaptcha = false
Dim privateKey
privateKey ="private key"
Dim VarString
VarString = _
"privatekey=" & privateKey & _
"&remoteip=" & Request.ServerVariables("REMOTE_ADDR")
& _
"&challenge=" &
Request.Form("recaptcha_challenge_field") & _
"&response=" &
Request.Form("recaptcha_response_field")
Dim objXmlHttp
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "POST", "http://api-verify.recaptcha.net/
verify", False
objXmlHttp.setRequestHeader "Content-Type", "application/x-www-
form-urlencoded"
objXmlHttp.send VarString
Dim ResponseString
ResponseString = split(objXmlHttp.responseText, vblf)
Set objXmlHttp = Nothing
if ResponseString(0) = "true" then
'They answered correctly - do something
IsGoodCaptcha = true
else
'They answered incorrectly
IsGoodCaptcha = false
ErrorCode = "&error=" & ResponseString(1)
end if
%>
<input name="Button" type="submit" value="Send Mail"
onclick="validate();return returnVal;">
The form works fine, validates the input in the form fields, creates
message to the sender with the values have been input and sends the
email BUT does not validate the reCAPTCHA.
Might need some more code in the submit button?
All help appreciated
<%@ Language="VBScript" %>
<%
Option Explicit
'Define some variables to be used on page
dim pubkey, privkey, challenge, form_response, show_form,
form_feedback, message, email_from, email_to, subject, test_captcha,
myserver, mydestination, url
'Customize your public and private keys and other variables
pubkey = "ENTER PUBLIC KEY HERE"
privkey = "ENTER PRIVATE KEY HERE"
myserver = "ENTER YOUR E-MAIL PROCESSING SERVER HERE"
mydestination = "ENTER YOUR DESTINATION EMAIL"
url = "ENTER FORM'S ACTION URL HERE, EG, demo.asp"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>reCAPTCHA Demo</title>
</head>
<body>
<%
'''''''''''''''''''''' BEGIN FUNCTIONS ''''''''''''''''''''''''
'Function to Test Captcha Field
challenge = Request.Form("recaptcha_challenge_field")
form_response = Request.Form("recaptcha_response_field")
function recaptcha_confirm(privkey,rechallenge,reresponse)
Dim VarString
VarString = _
"privatekey=" & privkey & _
"&remoteip=" & Request.ServerVariables("REMOTE_ADDR") & _
"&challenge=" & rechallenge & _
"&response=" & reresponse
Dim objXmlHttp
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "POST", "http://api-verify.recaptcha.net/verify",
False
objXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-
urlencoded"
objXmlHttp.send VarString
Dim ResponseString
ResponseString = split(objXmlHttp.responseText, vblf)
Set objXmlHttp = Nothing
if ResponseString(0) = "true" then
'They answered correctly
recaptcha_confirm = ""
else
'They answered incorrectly
recaptcha_confirm = ResponseString(1)
end if
end function
'Example Function to Send Email Using CDOSYS
function sendEmail( to_email, subject, message, from_email )
'send email
Dim cdoConfig, cdoMessage
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") =
2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
myserver
.Update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.Subject = subject
.From = from_email
.To = to_email
.TextBody = message
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
end function
'''''''''''''''''''''' END FUNCTIONS ''''''''''''''''''''''''
%>
<%
'''''''''' FORM REQUEST, PROCESSED ON POSTBACK ''''''''''''''
'Form posts back to this page
form_feedback = ""
show_form = true
if Request.Form("submit") <> "" AND Request.Form("submit") = "Send
Comment!" then
show_form = false
'Assemble message
subject = "Comment From reCAPTCHA Demo Page"
message = "Name: " & Request.Form("name") & vbcrlf & "Email: " &
Request.Form("email") & vbcrlf & "Comments: " &
Request.Form("comment")
'Enter destination e-mail
email_to = mydestination
'EXAMPLE OF BASIC ERROR PROCESSING
'Required - Email Address
if Request.Form("email") <> "" then
email_from = Request.Form("email")
else
form_feedback = form_feedback & "<li>Please enter your email
address.</li>"
show_form = true
end if
'Required - Name
if Request.Form("name") = "" then
form_feedback = form_feedback & "<li>Please enter your name.</li>"
show_form = true
end if
'Required - Correct Captcha Value
test_captcha = recaptcha_confirm(privkey, challenge,
form_response)
'response.write(test_captcha)
if test_captcha <> "" then
form_feedback = form_feedback & "<li>The entered text does not
match, please try again.</li>"
show_form = true
end if
'No Errors on Page, Send E-mail
if show_form = false then
call sendEmail( email_to, subject, message, email_from )
%>
<p>Your comment was sent successfully!</p>
<%
end if
end if
''''''''' END FORM REQUEST, PROCESSED ON POSTBACK ''''''''''''
if show_form = true then
'Display errors to user
if form_feedback <> "" then
%>
<ul style="background: #ffffcc;"><%=form_feedback%></ul>
<% end if
'''''''''''''''''' DISPLAY INITIAL FORM ''''''''''''''''''''''
%>
<h1>reCAPTCHA Demo</h1>
<!-- Make sure to set the form's action to postback to this page. -->
<form id="myform" action="<%=url%>" method="post">
<fieldset>
<legend>Please enter your comment below:</legend>
<table>
<tr>
<td><strong><label for="name">Name:</label></strong></td>
<td>
<input type="text" name="name" id="name" value="<
%=Request.Form("name")%>" size="40">
</td>
</tr>
<tr>
<td><strong><label for="email">Email:</label></strong></td>
<td>
<input type="text" name="email" id="email" value="<
%=Request.Form("email")%>" size="40">
</td>
</tr>
<tr>
<td colspan="2"><strong><label for="comment">Comments:</label></
strong></td>
</tr>
<tr>
<td colspan="2">
<textarea name="comment" id="comment" rows="10" cols="52"></
textarea>
</td>
</tr>
<tr>
<td colspan="2">
<%
' returns string the can be written where you would like the reCAPTCHA
function recaptcha_challenge_writer(publickey)
recaptcha_challenge_writer = "<script type=""text/javascript"">" & _
"var RecaptchaOptions = {" & _
" theme : 'clean'," & _
" tabindex : 0" & _
"};" & _
"</script>" & _
"<script type=""text/javascript"" src=""http://api.recaptcha.net/
challenge?k=" & publickey & """></script>" & _
"<noscript>" & _
"<iframe src=""http://api.recaptcha.net/noscript?k=" & publickey &
""" frameborder=""1""></iframe><br>" & _
"<textarea name=""recaptcha_challenge_field"" rows=""3""
cols=""40""></textarea>" & _
"<input type=""hidden"" name=""recaptcha_response_field""
value=""manual_challenge"">" & _
"</noscript>"
end function
dim myCaptcha
myCaptcha = recaptcha_challenge_writer(pubkey)
response.write(myCaptcha)
%>
<input type="submit" name="submit" id="submit" value="Send
Comment!">
</td>
</tr>
</table>
</fieldset>
</form>
<%
''''''''''''''''' END DISPLAY INITIAL FORM '''''''''''''''''''''
end if %>
</body>
</html>