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
 
The <cf_recaptcha action="check" ..> is what creates the form.recaptcha variable. So it should be on the action page, not the form.

* Note security keys xxx'd out

Code:
<cfif isDefined("form.submit")>
   <cf_recaptcha action="check"
      privateKey="xxxxxxxxx"
      publicKey="xxxxxxxx">
    <cfoutput><b>recaptcha says #form.recaptcha#/b></cfoutput>

   <cfif form.recaptcha>
         accepted. do one thing
    <cfelse>
         rejected. do something else
    </cfif>

</cfif>

----------------------------------
 
This form submits to itself...
I have this on the top
<cfif isDefined("form.entrydate")>
<cfquery datasource="ASME2" name="insert">
INSERT INTO wsfeedback
(entrydate, firstname, lastname, member_id)
VALUES
(#Now()#, '#form.firstname#', '#form.lastname#', '#form.member_id#')
</cfquery>
<CFINCLUDE template="test.cfm">
<cfabort>
</cfif>

Under this query I have
<cf_recaptcha action="check"
privateKey="xxxxxxxxx"
publicKey="xxxxxxxx">
<cfoutput><b>recaptcha says #form.recaptcha#/b></cfoutput>


Is this not right?
 
I have got it to work:) I did put in wrong place, that's why it didn't give me the right output. Now I will work on preventing to submit if the value is false. Thank you for your help. I might bother you again on this:) You are always a BIG help. I really appreciate it!
 
No. Think about what that code is doing. It is inserting *first*, then checking the captcha value. That does not make sense. You need to check the captcha value first. Then do the INSERT only if it is accepted.

Go back to your earlier example. All that is missing is the CFIF condition to "do something" if the value is accepted.

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

      <cfif isDefined("form.submit")>
         <cfoutput>recaptcha says #form.recaptcha#</cfoutput>
         <cfif form.recaptcha>
             accepted. do your INSERT here ...
         </cfif>
      </cfif>

--------
<form method="post" ...>
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">
</form>



----------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top