Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use reCaptcha in Cold Fusion form?

Status
Not open for further replies.

olchik

Programmer
Jan 6, 2006
93
US
Hello,

does anybody know how to use reCaptcha in CF form? I have found source code for CF but I cannot get it to work. If anybody knows how, please help...

Thank you
 
Well .. "does not work" could mean a lot of things :) Please

a) Post your code
b) Tell us what *is* happening now and how it differs from what you expect to happen ..

----------------------------------
 
Hello,

thank you for your response. Here is the code. It lets me submit without entering anything in reCaptcha field.

<cf_recaptcha action="check"
privateKey="6Ld7l7oSAAAAANeJkL7MGfEgB6AVYo7QHVXFkgaG"
publicKey="6Ld7l7oSAAAAAOxY9FHq-vpjMHh9IMARx04-8U-l">

<cfif isDefined("form.submit")>
<cfoutput>recaptcha says #form.recaptcha#</cfoutput>
</cfif>

--------
To protect against form SPAM, we're requiring that feedback form submissions be validated by entering the image value in the field below. If the image's value is too hard to read, press the refresh button to the right.</font>
</p><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
<!--- end part of recaptcha code --->
<cf_recaptcha
privateKey="6Ld7l7oSAAAAANeJkL7MGfEgB6AVYo7QHVXFkgaG"
publicKey="6Ld7l7oSAAAAAOxY9FHq-vpjMHh9IMARx04-8U-l">

<input type="Submit" name="submit">


Thank you

 
I understand that part. I can validate against empty field, but it also submits if I enter anything. How do I validate against random text?

Thank you
 
How would you tell the difference between "random text" and a valid entry? There are some obvious cases like all white space or maybe strings that consist of all the same letters. But beyond that it seems like trying to do what the captcha does already ..

----------------------------------
 
hmmm...so this validation is the only thing that I need to add for this code to work? Everything else looks fine?
 
Technically you should not need to add anything. From my very limited testing it returns "true" if you entered the correct value, otherwise it returns false. That should cover any wrong value, including entering nothing. So I am not sure what else you are looking for ...

----------------------------------
 
I am not looking for anything else. It just doesn't work for me and I don't know what am I doing wrong. He is a custom tag itself....

<cfsetting enablecfoutputonly="true">

<cfscript>
CHALLENGE_URL = " SSL_CHALLENGE_URL = " VERIFY_URL = "</cfscript>

<cfif not structKeyExists(attributes, "publicKey")>
<cfthrow type="RECAPTCHA_ATTRIBUTE"
message="recaptcha: required attribute 'publicKey' is missing">
</cfif>

<cfif not structKeyExists(attributes, "privateKey")>
<cfthrow type="RECAPTCHA_ATTRIBUTE"
message="recaptcha: required attribute 'privateKey' is missing">
</cfif>

<cftry>
<cfset sInvalidAttr="action not render|check">
<cfparam name="attributes.action" default="render">
<cfset sInvalidAttr="ssl not true|false">
<cfparam name="attributes.ssl" type="boolean" default="true">
<cfset sInvalidAttr="theme not red|white|blackglass">
<cfparam name="attributes.theme" default="red">
<cfset sInvalidAttr="tabIndex not numeric">
<cfparam name="attributes.tabIndex" type="numeric" default="0">
<cfcatch type="any">
<cfthrow type="RECAPTCHA_ATTRIBUTE"
message="recaptcha: attribute #sInvalidAttr#">
</cfcatch>
</cftry>

<cfif isDefined("form.recaptcha_challenge_field") and isDefined("form.recaptcha_response_field")>

<cftry>
<cfhttp url="#VERIFY_URL#" method="post" timeout="5" throwonerror="true">
<cfhttpparam type="formfield" name="privatekey" value="#attributes.privateKey#">
<cfhttpparam type="formfield" name="remoteip" value="#cgi.REMOTE_ADDR#">
<cfhttpparam type="formfield" name="challenge" value="#form.recaptcha_challenge_field#">
<cfhttpparam type="formfield" name="response" value="#form.recaptcha_response_field#">
</cfhttp>
<cfcatch>
<cfthrow type="RECAPTCHA_NO_SERVICE"
message="recaptcha: unable to contact recaptcha verification service on url '#VERIFY_URL#'">
</cfcatch>
</cftry>

<cfset aResponse = listToArray(cfhttp.fileContent, chr(10))>
<cfset form.recaptcha = aResponse[1]>
<cfset structDelete(form, "recaptcha_challenge_field")>
<cfset structDelete(form, "recaptcha_response_field")>

<cfif aResponse[1] eq "false" and aResponse[2] neq "incorrect-captcha-sol">
<cfthrow type="RECAPTCHA_VERIFICATION_FAILURE"
message="recaptcha: the verification service responded with error '#aResponse[2]#'. See for error meanings.">
</cfif>

<cfelse>

<cfset form.recaptcha = false>

</cfif>

<cfif attributes.action eq "render">

<cfif attributes.ssl>
<cfset challengeURL = SSL_CHALLENGE_URL>
<cfelse>
<cfset challengeURL = CHALLENGE_URL>
</cfif>

<cfoutput>
<script type="text/javascript">
<!--
var RecaptchaOptions = {
theme : '#attributes.theme#',
tabindex : #attributes.tabIndex#
};
//-->
</script>
<script type="text/javascript"
src="#challengeURL#/challenge?k=#attributes.publicKey#">
</script>
<noscript>
<iframe src="#challengeURL#/noscript?k=#attributes.publicKey#"
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>
</cfoutput>

</cfif>
<cfsetting enablecfoutputonly="false">


maybe I don't call in a right way???
 
I just need it to prevent from being submitted if the value is bad, but I don't know how to do it:-(
When I used Captcha (javascript source code) I just inserted it and it worked. I didn't have to add anything to it. But I was said Captcha is not good enough and I need to use reCaptcha, but I don't know how to get it to work...
 
I just need it to prevent from being submitted if the value is bad

I think you are misunderstanding how the tag is supposed to work.

"...The tag is not supposed to prevent the form from submitting - it is up to you in your own form action logic to check the boolean flag the tag adds to your form scope to accept or reject the submitted form..."


----------------------------------
 
Yes, it is enclosed in <cfform>

I don't know how to check the boolean flag. Could you please help me with it?
 
<cfif isDefined("form.submit")>
<cfoutput>recaptcha says #form.recaptcha#</cfoutput>
</cfif>
[/code]

#form.recaptcha# is a simple true/false value. Just check it and do one thing if it is true, another if it is false.

Code:
<cfif isDefined("form.submit")>
    <cfif form.recaptcha>
         accepted. do one thing
    <cfelse>
         rejected. do something else 
    </cfif>
</cfif>

----------------------------------
 
form.recaptcha isn't showing. When I tried to put it on auction page, it gives me "Element RECAPTCHA is undefined in FORM" error
 
This is the whole form, I have put output for captcha on test.cfm

<cfif isDefined("form.entrydate")>
<cfquery datasource="ASME2" name="insert">
INSERT INTO wsfeedback
(entrydate, refurl, reftitle, email, feedbacktype, feedbackregard, <cfif IsDefined("form.feedbackregard_specify")>feedbackregard_specify,</cfif> feedback, <cfif IsDefined("form.member")>member,</cfif> <cfif IsDefined("form.comptype")>comptype,</cfif> <cfif IsDefined("form.browser")>browser,</cfif> firstname, lastname, member_id)
VALUES
(#Now()#, '#form.prevurl#', '#form.reftitle#', '#form.email#', '#form.feedbacktype#', '#form.feedbackregard#', <cfif IsDefined("form.feedbackregard_specify")>'#form.feedbackregard_specify#',</cfif> '#form.feedback#', <cfif IsDefined("form.member")>'#form.member#',</cfif> <cfif IsDefined("form.comptype")>'#form.comptype#',</cfif> '#form.browser#', '#form.firstname#', '#form.lastname#', '#form.member_id#')
</cfquery>
<CFINCLUDE template="test.cfm">
<cfabort>
</cfif>
<Cfoutput>
<cfset currURL = "#CGI.HTTPS#">

</CFOUTPUT><cfoutput><!--- <cfif #currURL# is "off">
<cflocation url="</cfif> --->
<cfif IsDefined("CGI.HTTP_REFERER")><cfif #CGI.HTTP_REFERER# is not "">
<cfhttp method="get" redirect="true" url="#CGI.HTTP_REFERER#" throwonerror="true"></cfhttp>
<cfset st = REFindNoCase("<title>.*?</title>",cfhttp.fileContent,1,"True")>
<cfif st.pos[1] is not 0>
<cfset wholetag="#mid(cfhttp.fileContent, st.pos[1], st.len[1])#">
<cfset begintitletag="#left(mid(cfhttp.fileContent, st.pos[1], st.len[1]), 7)#">
<cfset endtitletag ="#right(mid(cfhttp.fileContent, st.pos[1], st.len[1]), 8)#">
<cfset removedbeginning="#RemoveChars(wholetag, 1, 7)#">
<cfset titlelen="#Evaluate(Len(removedbeginning) - Len(endtitletag))#">
<cfif titlelen is not "0">
<cfset pagetitle="#left(removedbeginning, titlelen)#">
<cfelse>
<cfset pagetitle="">
</cfif></cfif>
</cfif></cfif></cfoutput>
</p>
<html>

<head>

<title>Web Site Feedback Form</title>
<style type="text/css">
.fstyle
{
display: none;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">


function validate(f) {

if(f.feedbackregard.selectedIndex=="")
{
alert("Please tell us what is the Feedback regarding");
f.feedbackregard.focus();
return false;
}
if(f.feedbackregard.selectedIndex=="6")
{
if(f.feedbackregard_specify.value=="")
{
alert("Please tell us what is the Feedback regarding?");
f.feedbackregard_specify.focus();
return false;
}
}
if(f.feedback.value=="")
{
alert("Please let us know your thoughts");
f.feedback.focus();
return false;
}
if( ! (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test
(f.email.value)))
{

alert("Please enter valid Email address!")
return false;
}

return true;

}
</script>


<script type="text/javascript" src="multiValue.js"></script>


</head>


<body bgcolor="#FFFFFF">
<!--- recaptcha code--->

<cf_recaptcha action="check"
privateKey="6Ld7l7oSAAAAANeJkL7MGfEgB6AVYo7QHVXFkgaG"
publicKey="6Ld7l7oSAAAAAOxY9FHq-vpjMHh9IMARx04-8U-l">


<p ><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<cfoutput><cfif #Left(CGI.HTTP_REFERER, 26)# is "<table width="740"><tr><td><img src="images/15798.jpg"></td></tr><!--- <tr><td><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
</font></td></tr> ---></table>
<cfelseif #Left(CGI.HTTP_REFERER, 24)# is "<table border="0" width="640" cellspacing="5" cellpadding="2" ><tr><td><img src="images/asmenewslogo.jpg"></td></tr>
<!--- <tr><td><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
</font></td></tr> ---></table>
<cfelse>ASME would like to know what you think. Let us know by submitting the following form. <br></font></b><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>All
fields with <font color="ff0000">*</font> are required.</cfif></cfoutput><Br><!--- <Cfoutput>#currURL#</CFOUTPUT> ---> </b></font></p>


<cfform method="post" action="feedbackform.cfm" name="form" onSubmit="return validate(_CF_this)">

<input type="hidden" name="id">
<input type="hidden" name="entrydate" value="#DateFormat(Now(),"mm/dd/yyyy")#">
<p class="fstyle"><input name="subject" type="text" value=""/> </p>
<cfoutput>
<input type="hidden" name="prevurl" value="#CGI.HTTP_REFERER#">
<input type="hidden" name="browser" value="#CGI.HTTP_USER_AGENT#">
<table border="0" width="640" cellspacing="5" cellpadding="2" >
<cfoutput>
<cfif (#Left(CGI.HTTP_REFERER, 26)# is " or (#Left(CGI.HTTP_REFERER, 24)# is " <tr>
<td width="30%" valign="top" height="163" bgcolor="F7F7F7"><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
Your feedback helps us determine content and areas of coverage. Please take a moment to comment on the article you have just read.<font color="ff0000">*</font></td><td valign="top">
<textarea name="feedback" cols="40" rows="8"></textarea>
</font></td>
</tr>
<tr>
<td width="30%" bgcolor="F7F7F7"><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
First Name: </td><td>
<input type="text" name="firstname" size="25">
</font></td>
</tr>
<tr>
<td width="30%" bgcolor="F7F7F7"><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
Last Name:</td><td>
<input type="text" name="lastname" size="25">
</font></td>
</tr>
</cfif>
</cfoutput>
<tr>
<td width="30%" bgcolor="F7F7F7" ><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
Please enter Page Title/URL: </td><td>
<cfoutput><input type="text" name="reftitle" size="50" value="#CGI.HTTP_REFERER#"></cfoutput><!--- <cfif IsDefined("CGI.HTTP_REFERER")><cfif IsDefined("pagetitle") and pagetitle is not "">value="#pagetitle#"<cfelse></cfif></cfif> --->
</font></td>
</tr>
<tr>
<td width="30%" valign="top" bgcolor="F7F7F7"><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
Feedback type:<font color="ff0000">*</font></td><td>
<select id="feedbacktype" name="feedbacktype" onChange="ShowReg2(this.selectedIndex)">
<option value='0'> -- select--
<option value="Report a bug"> Report a bug</option>
<option value="Complaint"> Complaint</option>
<option value="Compliment"> Compliment</option>
<option value="Comment"> Comment</option>
<option value="Question"> Question</option>
</select>
<br><div id="Report a bug" style="display:none">
<font face="Verdana, Arial, Helvetica, sans-serif"size="2">What computer platform are you using?</font>
<input type="text" name="Comptype" value=""></div>
<div id="Complaint" style="display:none">
<input type="hidden" name="Complaint" value=""></div>
<div id="Compliment" style="display:none">
<input type="Hidden" name="Compliment" value=""></div>
<div id="Comment" style="display:none">
<input type="hidden" name="Comment" value=""></div>
<div id="Question" style="display:none">
<input type="hidden" name="Question" value=""></div>
</td>
</tr>
tr>
<td width="30%" valign="top" bgcolor="F7F7F7"><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
What is the Feedback regarding:<font color="ff0000">*</font> </td><td>
<!--- <textarea name="comment1" cols="40" rows="8"></textarea> --->
<select name="feedbackregard" onChange="ShowReg(this.selectedIndex)">
<option value=""> -- select--
<option value="Membership">Membership</option>
<option value="Product">Product</option>
<option value="Event">Event</option>
<option value="Service">Service</option>
<option value="ASME Search Engine">ASME Search Engine</option>
<option value="Other">Other</option>
</select><br>
<div id="Membership" style="display:none">
<input type="hidden" name="membernum" value=""></div>
<div id="Product" style="display:none">
<input type="Hidden" name="product" value=""></div>
<div id="Event" style="display:none">
<input type="hidden" name="event" value=""></div>
<div id="Service" style="display:none">
<input type="hidden" name="Service" value=""></div>
<div id="ASME Search Engine" style="display:none">
<font face="Verdana, Arial, Helvetica, sans-serif"size="2">What specific keyword or phrase did you enter into the search engine? </font><input type="text" name="feedbackregard_specify" value="" size="40">
</div>
<div id="Other" style="display:none">
<font face="Verdana, Arial, Helvetica, sans-serif"size="2">If other, please describe</font> <input type="text" name="feedbackregard_specify" size="25">
</td>
</tr>
<tr>
<td width="30%" valign="top" height="163" bgcolor="F7F7F7"><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
Please let us know your thoughts <font color="ff0000">*</font> </td><td valign="top">
<textarea name="feedback" cols="40" rows="8"></textarea>
</font></td>
</tr>
<cfoutput>
<cfif (#Left(CGI.HTTP_REFERER, 26)# is not " and (#Left(CGI.HTTP_REFERER, 24)# is not "
<tr>
<td width="30%" bgcolor="F7F7F7"><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
First Name: </td><td>
<input type="text" name="firstname" size="25">
</font></td>
</tr>
<tr>
<td width="30%" bgcolor="F7F7F7"><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
Last Name:</td><td>
<input type="text" name="lastname" size="25">
</font></td>
</tr>
</cfif>
</cfoutput>

<tr>
<td width="30%" bgcolor="F7F7F7"><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
Email Address:<font color="ff0000">*</font></td><td>
<input type="text" name="email" size="25">
</font></td>
</tr>
<tr>
<td width="30%" valign="top" height="32" bgcolor="F7F7F7"><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
Are you a member of ASME? </td><td>

<input type="radio" name="member" value="Yes">
<font face="Verdana, Arial, Helvetica, sans-serif"size="2">Yes </font>
<input type="radio" name="member" value="No">
<font face="Verdana, Arial, Helvetica, sans-serif"size="2">No </font>
<cfoutput>
<cfif (#Left(CGI.HTTP_REFERER, 26)# is not " or (#Left(CGI.HTTP_REFERER, 24)# is not " <input type="radio" name="member" value="Student">
<font face="Verdana, Arial, Helvetica, sans-serif"size="2">I am a student member</font><br>
</font></td>
</tr>

<tr>
<td width="30%" valign="top" bgcolor="F7F7F7">
<font face="Verdana, Arial, Helvetica, sans-serif"size="2">If submitting a membership related question please include your membership ID.
</td><td valign="top">
<input type="Text" name="member_id" size="25">
</font> </td>
</tr>
</cfif>
</cfoutput>
<tr>
<td width="100%" colspan="2">
<div ><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
</font></div>
</td>
</tr>
<tr>
<td colspan="2">

<div >


<table bgcolor="#c0c0c0"><tr><td>
<p><font face="Verdana, Arial, Helvetica, sans-serif"size="1">
To protect against form SPAM, we're requiring that feedback form submissions be validated by entering the image value in the field below. If the image's value is too hard to read, press the refresh button to the right.</font>
</p><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
<!--- end part of recaptcha code --->
<cf_recaptcha
privateKey="6Ld7l7oSAAAAANeJkL7MGfEgB6AVYo7QHVXFkgaG"
publicKey="6Ld7l7oSAAAAAOxY9FHq-vpjMHh9IMARx04-8U-l">

<input type="Submit" name="submit">

<br>

</font></td></tr></table>

</cfform>

<img src="../images/Plock.gif" alt="Secure" width="20" height="20"></div>
</td>
</tr>
<tr>
<td colspan="2">
<cfoutput>
<cfif (#Left(CGI.HTTP_REFERER, 26)# is not " or (#Left(CGI.HTTP_REFERER, 24)# is " face="Verdana, Arial, Helvetica, sans-serif"size="1">All
data collected is for ASME internal use only.<br></cfif></cfoutput>
</td>

</tr>
</table>

</body>

</html>
 
<body bgcolor="#FFFFFF">
<!--- recaptcha code--->

<cf_recaptcha action="check"
privateKey="6Ld7l7oSAAAAANeJkL7MGfEgB6AVYo7QHVXFkgaG"
publicKey="6Ld7l7oSAAAAAOxY9FHq-vpjMHh9IMARx04-8U-l">

<cfform method="post" action="feedbackform.cfm" name="form" onSubmit="return validate(_CF_this)">

<input type="hidden" name="id">
<input type="hidden" name="entrydate" value="#DateFormat(Now(),"mm/dd/yyyy")#">
<tr>
<td width="30%" bgcolor="F7F7F7"><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
First Name: </td><td>
<input type="text" name="firstname" size="25">
</font></td>
</tr>
<tr>
<td width="30%" bgcolor="F7F7F7"><font face="Verdana, Arial, Helvetica, sans-serif"size="2">
Last Name:</td><td>
<input type="text" name="lastname" size="25">
</font></td>
</tr>
<cf_recaptcha
privateKey="6Ld7l7oSAAAAANeJkL7MGfEgB6AVYo7QHVXFkgaG"
publicKey="6Ld7l7oSAAAAAOxY9FHq-vpjMHh9IMARx04-8U-l">

<input type="Submit" name="submit">
</td></tr></table>

</cfform>

This code I have put on the page that appears after form is submitted...
<cfif isDefined("form.submit")>
<cfoutput><b>recaptcha says #form.recaptcha#</b></cfoutput>
</cfif>


Thank you being patient with me...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top