Pluf_Form_Field_ReCaptcha Class Reference

Inheritance diagram for Pluf_Form_Field_ReCaptcha:

Pluf_Form_Field

List of all members.

Public Member Functions

 clean ($value)

Static Public Member Functions

static httpPost ($host, $path, $data, $port=80)
static qsencode ($data)
static checkAnswer ($privkey, $remoteip, $challenge, $response, $extra_params=array())

Public Attributes

 $widget = 'Pluf_Form_Widget_ReCaptcha'
 $privkey = ''
 $remoteip = ''
 $extra_params = array()


Detailed Description

Add ReCaptcha control to your forms.

You need first to get a ReCaptcha account, create a domain and get the API keys for your domain. Check http://recaptcha.net/ for more information.

The recaptcha field needs to know the IP address of the user submitting the form and if the request is made over SSL or not. This means that you need to provide the $request object in the extra parameters of your form.

To add the ReCaptcha field to your form, simply add the following to your form object (note the use of $extra['request']):

 $ssl = (!empty($extra['request']->SERVER['HTTPS']) 
         and $extra['request']->SERVER['HTTPS'] != 'off');

 $this->fields['recaptcha'] = new Pluf_Form_Field_ReCaptcha(
                       array('required' => true,
                               'label' => __('Please solve this challenge'),
                               'privkey' => 'PRIVATE_RECAPTCHA_KEY_HERE',
                               'remoteip' => $extra['request']->remote_addr,
                               'widget_attrs' => array(
                                      'pubkey' => 'PUBLIC_RECAPTCHA_KEY_HERE',
                                      ),
                                      ));
 

Then in your template, you simply need to add the ReCaptcha field:

 {if $form.f.recaptcha.errors}{$form.f.recaptcha.fieldErrors}{/if}
 {$form.f.recaptcha|safe}
 

Based on http://recaptcha.googlecode.com/files/recaptcha-php-1.10.zip

Copyright (c) 2007 reCAPTCHA -- http://recaptcha.net AUTHORS: Mike Crawford Ben Maurer


Member Function Documentation

Pluf_Form_Field_ReCaptcha::clean ( value  ) 

Validate some possible input for the field.

Parameters:
mixed Value to clean.
Returns:
mixed Cleaned data or throw a Pluf_Form_Invalid exception.

Reimplemented from Pluf_Form_Field.

static Pluf_Form_Field_ReCaptcha::httpPost ( host,
path,
data,
port = 80 
) [static]

Submits an HTTP POST to a reCAPTCHA server

Parameters:
string Host
string Path
array Data
int port (80
Returns:
array response

static Pluf_Form_Field_ReCaptcha::qsencode ( data  )  [static]

Encodes the given data into a query string format

Parameters:
array Array of string elements to be encoded
Returns:
string Encoded request

static Pluf_Form_Field_ReCaptcha::checkAnswer ( privkey,
remoteip,
challenge,
response,
extra_params = array() 
) [static]

Calls an HTTP POST function to verify if the user's guess was correct

Parameters:
string $privkey
string $remoteip
string $challenge
string $response
array $extra_params an array of extra variables to post to the server
Returns:
ReCaptchaResponse


Member Data Documentation

Pluf_Form_Field_ReCaptcha::$widget = 'Pluf_Form_Widget_ReCaptcha'

Widget. The way to "present" the field to the user.

Reimplemented from Pluf_Form_Field.

Pluf_Form_Field_ReCaptcha::$privkey = ''

Pluf_Form_Field_ReCaptcha::$remoteip = ''

Pluf_Form_Field_ReCaptcha::$extra_params = array()


The documentation for this class was generated from the following file:

Generated on Wed Feb 3 15:44:52 2010 for Pluf by  doxygen