Asp forms

915 views
Skip to first unread message

Apostolos

unread,
Oct 7, 2007, 12:21:14 PM10/7/07
to reCAPTCHA
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 Support

unread,
Oct 7, 2007, 12:23:25 PM10/7/07
to reca...@googlegroups.com

Apostolos

unread,
Oct 8, 2007, 4:02:32 PM10/8/07
to reCAPTCHA
Thank you up to now
I have come almost to the end
You can see my test form at http://www.easytraveller.gr/contactNEW.asp
As you can see from the code just after the reCAPTCHA I have the
submit button which does the validation of the form for the requested
fields
<input name="Button" type="submit" value="Send Mail"
onclick="validate();return returnVal;" >

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

reCAPTCHA Support

unread,
Oct 8, 2007, 4:06:06 PM10/8/07
to reca...@googlegroups.com
reCAPTCHA needs to be validated on the server, not the client.

Apostolos

unread,
Oct 8, 2007, 4:11:04 PM10/8/07
to reCAPTCHA
Does this mean I have to upload something on the server?


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

tomk

unread,
Oct 8, 2007, 5:53:03 PM10/8/07
to reCAPTCHA
I'm having similar trouble with this feature. Most of the steps in
setting this up have some simple script examples that I can cut,
paste, and tweak. The 'Verifying the reCAPTCHA Solution' doesn't seem
to have any script examples.

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

Apostolos

unread,
Oct 9, 2007, 4:27:20 PM10/9/07
to reCAPTCHA
Please find here the code as appears in the form

<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

mrkshrt

unread,
Oct 12, 2007, 9:54:09 PM10/12/07
to reCAPTCHA
On Oct 9, 3:27 pm, Apostolos <i...@easytraveller.gr> wrote:
> Please find here the code as appears in the form
I worked off of the examples and created a couple of functions that
might be useful for 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

%>

Apostolos

unread,
Oct 25, 2007, 3:11:16 AM10/25/07
to reCAPTCHA
Please help Almost done!

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

Apostolos

unread,
Oct 25, 2007, 11:46:34 AM10/25/07
to reCAPTCHA

Shaun3180

unread,
Nov 12, 2007, 12:52:40 PM11/12/07
to reCAPTCHA
Great work Mark; I went ahead and made a simple one page comment form
to create an accessible/valid XHTML CAPTCHA example (using your code
and CDOSYS for e-mail processing) in vbscript:

<%@ 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>

Julie

unread,
Nov 19, 2007, 5:21:53 PM11/19/07
to reCAPTCHA
Shaun: Thanks so much for this. I've been playing with snippets of
code for days now - lol - and wasn't getting anything to work, and
didn't have a "complete" example to work from. This suits my purposes
perfect, as I've gotta stick this puppy on a zillion different forms
for a client.

Thanks again.

Julie
> > %>- Hide quoted text -
>
> - Show quoted text -

albertomac

unread,
Dec 1, 2007, 9:30:43 AM12/1/07
to reCAPTCHA
Thanks Mark and Shaun for this great contribution.
Reply all
Reply to author
Forward
0 new messages