Download Plugin (zip)

Stats

Version

1.1.4

Wheels Compatibility

1.1.5, 1.1.4, 1.1.3, 1.1.2, 1.1.1, 1.1, 1.0.5, 1.0.4, 1.0.3, 1.0.2, 1.0.1, 1.0

Downloads

368

Last Updated

January 12, 2012

About Plugins

Plugins allow you to extend or modify default Wheels application behavior. To use, you just drop the zip file into your plugins directory and reload your application.

Read Using and Creating Plugins for more information.

reCAPTCHA on Wheels

With 2 simple functions, you can use Google's reCAPTCHA service to provide CAPTCHA validation on your forms.

Author

Chris Peters

Project Home

http://github.com/liquifusion/reCAPTCHA-on-Wheels

Description

reCAPTCHA is unique in that users solving the CAPTCHAs are helping universities and services like Google Book Search scan words from books that weren't picked up properly by OCR technology.

Credits

This plugin is based on code from the ColdFusion reCAPTCHA tag by Robin Hilliard.

Usage/Examples

There are 3 components to using reCAPTCHA in your Wheels application:

  • Configuration
  • Display of the reCAPTCHA widget
  • Validation of user input

Configuration

First, you need to obtain an API key from reCAPTCHA.net. You'll need to set up keys for each of your environments, so you may need one for your development domain and your production domain, for example.

Once you obtain public and private keys, you should set these values in your different environments' config files (config/design/settings.cfm, config/production/settings.cfm, etc.):

<--- Replace values with the keys assigned to you --->
<cfset application.reCaptcha.publicKey = "OEMy3RGbcwAAAAAAC0zu2ztLCSEHeoiOt6LfJpAU">
<cfset application.reCaptcha.privateKey = "F2IANxAfzJAu6LApgLb65q_F0hP6LAAAUAX1A-hV">

If you prefer setting your custom configurations in events/onapplicationstart.cfm instead, you could also create code similar to this in that file:

<--- reCAPTCHA --->
<cfswitch expression="#get('environment')#">
<cfcase value="design">
<cfset application.reCaptcha.publicKey = "OEMy3RGbcwAAAAAAC0zu2ztLCSEHeoiOt6LfJpAU">
<cfset application.reCaptcha.privateKey = "F2IANxAfzJAu6LApgLb65q_F0hP6LAAAUAX1A-hV">
</cfcase>
<cfcase value="production">
<cfset application.reCaptcha.publicKey = "RGbcwtLCOEMyAiOtAA6LfJpAUAC0zu2z3SEAAHeo">
<cfset application.reCaptcha.privateKey = "Au6LApghP6LAAAUX1A-LF2AfzJAb60hVIAN5q_Fx">
</cfcase>
</cfswitch>

You could always have cfswitch evaluate the current domain name instead of the Wheels environment too if that's your preference.

Display of the reCAPTCHA Widget

Just use the showCaptcha() function to display the widget in your form.

<--- At top of view --->
<cfparam name="captchaError" type="boolean" default="false">

<--- In form --->
<cfoutput>
#showCaptcha(captchaError=captchaError)#
</cfoutput>

The showCaptcha() function accepts 4 optional arguments.

Arguments for showCaptcha()
Argument Type Required Default Description
label string false Type the two words: Label to use for reCAPTCHA field.
ssl boolean false false Whether or not your form is served over SSL.
theme string false clean reCAPTCHA theme to use. Choices are clean, red, white, and blackglass.
captchaError boolean false false Whether or not the field should be surrounded with <span class="field-with-errors">. (This HTML tag is determined by the default setting for textField()'s errorElement argument. See the Function Settings section of the Configuration and Defaults chapter for more information.)

Validation of User Input

You use the validateCaptcha() function within your controller action to validate the user's input. It will return true if the test passed and false if not.

Here is an example:

<--- Build comment object --->
<cfset comment = model("comment").new(params.comment)>

<--- If CAPTCHA validated --->
<cfif validateCaptcha()>
<cfset comment.save()>
<cfset flashInsert(success="Comment submitted successfully.")>
<cfset redirectTo(action="post")>
<--- CAPTCHA didn't validate --->
<cfelse>
<cfset captchaError = true>
<cfset renderPage(action="post")>
</cfif>

Configuration for Offline Development

Sometimes you need to run your application without access to the Internet. And the reCAPTCHA widget and validation service both require a connection to the Internet! Maybe you're building your application while on the plane or in the airport.

We have a setting that allows for offline development. In your configuration, simply set application.hasInternetAccess to false.

This will cause reCAPTCHA on Wheels to show this text in place of the widget:

[NO INTERNET MODE] reCAPTCHA would go here

In this mode, the validateCaptcha() function will always return true as well so that reCAPTCHA functionality will not get in the way of testing the rest of your form.

When your application's environment is set to testing or production, this setting will always be overriden to true, so do not fear of accidentally forgetting to change it back to true before deploying to staging or production.

Change Log

Version 1.1.4—July 29, 2011 Download

  • Adds Wheels 1.1.4 and 1.1.5 compatibility.
  • Wheels compatibility: 1.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5.

Version 1.1.3—April 10, 2011 Download

  • Adds Wheels 1.1.3 compatibility.
  • Wheels compatibility: 1.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1, 1.1.1, 1.1.2, 1.1.3.

Version 1.1.2—February 8, 2011 Download

  • Adds Wheels 1.1.2 compatibility.
  • Wheels compatibility: 1.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1, 1.1.1, 1.1.2.

Version 1.1.1—November 22, 2010 Download

  • Added Wheels 1.1.1 compatibility.
  • Wheels compatibility: 1.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1, 1.1.1.

Version 0.3—November 9, 2010 Download

  • Tested for Wheels 1.1 compatibility.
  • Wheels compatibility: 1.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1.

Version 0.2—February 2, 2010 Download

  • Fixed a bug in validateCaptcha(). It was throwing an error and always failing.
  • Wheels compatibility: 1.0.

Version 0.1—November 26, 2009 Download

  • Initial release.
  • Wheels compatibility: 1.0.