DMXzone reCAPTCHA Support Product Page
Solved
ASP integration - initial newCaptcha variable blank
Reported 13 Dec 2011 06:08:24
1
has this problem
13 Dec 2011 06:08:24 Kent Angel posted:
I'm trying to integrate reCaptcha into an ASP form using your extension.I have followed the Google instructions for Classic ASP here:
code.google.com/apis/recaptcha/docs/asp.html
Using the Google example returns the initial form and validation check works correctly.
eg. 210.247.239.227/captcha2.asp
Replacing the Google ASP script with the DMX code does not bring up the initial form.
eg. 210.247.239.227/captcha1.asp
The "newCaptcha" variable appears to be blank initially, whereas the Google script sets the newCaptcha to "True" by default.
How can the example from Google (code.google.com/apis/recaptcha/docs/asp.html) be modified to work with the DMX code?
Official Solution
Replied 23 Jan 2012 14:55:06
Hi Kent,
First please do not use the the Google ReCAPTCHA samples - they won't work. Stick to the code that our extensions generates.
Second to retain a form field value after the form is submitted is something generic that can be done like this:
add a value to the input field in ASP like this:
for PHP it will be something like:
Greetings,
George
First please do not use the the Google ReCAPTCHA samples - they won't work. Stick to the code that our extensions generates.
Second to retain a form field value after the form is submitted is something generic that can be done like this:
add a value to the input field in ASP like this:
<input type="text" name="Email" size="40" value="<%= Response.Form("Email") %>" class="textbox"/>
for PHP it will be something like:
<input type="text" name="Email" size="40" value="<?php echo isset($_POST["Email"]) ? $_POST["Email"] : '' ?>" class="textbox"/>
Greetings,
George
Replies
Replied 13 Dec 2011 09:32:36
13 Dec 2011 09:32:36 Teodor Kuduschiev replied:
Hello Kent,
can you please tell me what do you mean by: "Replacing the Google ASP script with the DMX code" and if you followed the video tutorial about using the extension?
can you please tell me what do you mean by: "Replacing the Google ASP script with the DMX code" and if you followed the video tutorial about using the extension?
Replied 13 Dec 2011 13:16:32
13 Dec 2011 13:16:32 Kent Angel replied:
captcha2.asp (Google API example) has the following code:
captcha1.asp (the DMX version) has the same form and conditional if statement in the body, but instead had the DMX ASP script functions/includes inserted as per the "Using DMXzone reCAPTCHA" instructional video.
Here is the code for the DMX version of the form:
Please note: I have hidden the private/public keys in the code above, but they are both set the same in the actual examples.
Also, some of the code formatting/ASP script block delimeters above are not showing correctly in the forum "code" blocks.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> < % recaptcha_challenge_field = Request("recaptcha_challenge_field") recaptcha_response_field = Request("recaptcha_response_field") recaptcha_public_key = "{hidden}" ' your public key recaptcha_private_key = "{hidden}" ' your private key function recaptcha_challenge_writer() recaptcha_challenge_writer = _ "<script type=""text/javascript"">" & _ "var RecaptchaOptions = {" & _ " theme : 'white'," & _ " tabindex : 0" & _ "};" & _ "</script>" & _ "<script type=""text/javascript"" src=""http://www.google.com/recaptcha/api/challenge?k=" & recaptcha_public_key & """></script>" & _ "<noscript>" & _ "<iframe src=""http://www.google.com/recaptcha/api/noscript?k=" & recaptcha_public_key & """ frameborder=""1""></iframe><>" & _ "<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(rechallenge,reresponse) Dim VarString VarString = _ "privatekey=" & recaptcha_private_key & _ "&remoteip=" & Request.ServerVariables("REMOTE_ADDR") & _ "&challenge=" & rechallenge & _ "&response=" & reresponse Dim objXmlHttp Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP") objXmlHttp.open "POST", "http://www.google.com/recaptcha/api/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 recaptcha_confirm = "" else recaptcha_confirm = ResponseString(1) end if end function server_response = "" newCaptcha = True if (recaptcha_challenge_field <> "" or recaptcha_response_field <> "") then server_response = recaptcha_confirm(recaptcha_challenge_field, recaptcha_response_field) newCaptcha = False end if %> <!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=iso-8859-1" /> <title>Untitled Document</title> </head> <body> < %response.Write("<p>(server_response: "&server_response&") (newCaptcha: "&newCaptcha&")</p>") if server_response <> "" or newCaptcha then %> <% if newCaptcha = False then %> [h4]CAPTCHA code verification was incorrect![/h4] <% end if %> <form action="captcha2.asp" method="post"> <fieldset> <label><font color="#FF6600">*</font>Name:</label><br/> <input type="text" name="Name" size="40" class="textbox"/><br/> <label><font color="#FF6600">*</font>E-Mail:</label><br/> <input type="text" name="Email" size="40" class="textbox"/> </fieldset> <fieldset> <%=recaptcha_challenge_writer()%> <p><input type="submit" value="Submit" /></p> </fieldset> </form> <% else %> [h4]CAPTCHA IS CORRECT![/h4] <%end if%> </body> </html>
captcha1.asp (the DMX version) has the same form and conditional if statement in the body, but instead had the DMX ASP script functions/includes inserted as per the "Using DMXzone reCAPTCHA" instructional video.
Here is the code for the DMX version of the form:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!--#include virtual="/ScriptLibrary/dmxReCAPTCHA.asp" --> < %Dim MM_editAction MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")) If (Request.QueryString <> "") Then MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString) End If ' boolean to abort record edit Dim MM_abortEdit MM_abortEdit = false %> < %' DMXzone reCAPTCHA 1.0.1 Dim theCAPTCHA Set theCAPTCHA = new dmxReCAPTCHA theCAPTCHA.PrivateKey = "{hidden}" theCAPTCHA.PublicKey = "{hidden}" theCAPTCHA.Construct %> <!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=iso-8859-1" /> <title>Untitled Document</title> </head> <body> < %response.Write("<p>(server_response: "&server_response&") (newCaptcha: "&newCaptcha&")</p>") if server_response <> "" or newCaptcha then %> <% if newCaptcha = False then %> [h4]CAPTCHA code verification was incorrect![/h4] <% end if %> <form action="captcha1.asp" method="post"> <fieldset> <label><font color="#FF6600">*</font>Name:</label><br/> <input type="text" name="Name" size="40" class="textbox"/><br/> <label><font color="#FF6600">*</font>E-Mail:</label><br/> <input type="text" name="Email" size="40" class="textbox"/> </fieldset> <fieldset> <p> </p> <%= theCAPTCHA.getControl("white","en") %> <p> <input type="submit" value="Submit" /> </p> </fieldset> </form> <% else %> [h4]CAPTCHA IS CORRECT![/h4] <%end if%> </body> </html>
Please note: I have hidden the private/public keys in the code above, but they are both set the same in the actual examples.
Also, some of the code formatting/ASP script block delimeters above are not showing correctly in the forum "code" blocks.
Edited by - Kent Angel on 13 Dec 2011 13:20:21
Replied 23 Jan 2012 14:55:06
23 Jan 2012 14:55:06 George Petrov replied:
Hi Kent,
First please do not use the the Google ReCAPTCHA samples - they won't work. Stick to the code that our extensions generates.
Second to retain a form field value after the form is submitted is something generic that can be done like this:
add a value to the input field in ASP like this:
for PHP it will be something like:
Greetings,
George
First please do not use the the Google ReCAPTCHA samples - they won't work. Stick to the code that our extensions generates.
Second to retain a form field value after the form is submitted is something generic that can be done like this:
add a value to the input field in ASP like this:
<input type="text" name="Email" size="40" value="<%= Response.Form("Email") %>" class="textbox"/>
for PHP it will be something like:
<input type="text" name="Email" size="40" value="<?php echo isset($_POST["Email"]) ? $_POST["Email"] : '' ?>" class="textbox"/>
Greetings,
George