\Pluf_Form_Field_ReCaptcha

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

Summary

Methods
Properties
Constants
__construct()
clean()
setDefaultEmpty()
multiClean()
widgetAttrs()
httpPost()
qsencode()
checkAnswer()
$class
$widget
$label
$required
$help_text
$initial
$choices
$hidden_widget
$value
$multiple
$privkey
$remoteip
$extra_params
No constants found
No protected methods found
$empty_values
N/A
No private methods found
No private properties found
N/A

Properties

$class

$class : 

Store the name of the class.

Type

$widget

$widget : 

Widget.

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

Type

$label

$label : 

Type

$required

$required : 

< The label of the field.

Type

$help_text

$help_text : 

< Allowed to be blank.

Type

$initial

$initial : 

< Help text for the field.

Type

$choices

$choices : 

< Default value when empty.

Type

$hidden_widget

$hidden_widget : 

Type

$value

$value : 

Type

$multiple

$multiple : 

Returning multiple values (select multiple etc.)

Type

$privkey

$privkey : 

Type

$remoteip

$remoteip : 

Type

$extra_params

$extra_params : 

Type

$empty_values

$empty_values : 

Type

Methods

__construct()

__construct(  $params = array()) 

Constructor.

Example: $field = new Your_Field(array('required'=>true, 'widget'=>'Pluf_Form_Widget_TextInput', 'initial'=>'your name here', 'label'=>__('Your name'), 'help_text'=>__('You are?'));

Parameters

$params

clean()

clean(  $value) : mixed

Validate some possible input for the field.

Parameters

$value

Returns

mixed —

Cleaned data or throw a Pluf_Form_Invalid exception.

setDefaultEmpty()

setDefaultEmpty(  $value) : mixed

Set the default empty value for a field.

Parameters

$value

Returns

mixed —

Value

multiClean()

multiClean(  $value) : array

Multi-clean a value.

If you are getting multiple values, you need to go through all of them and validate them against the requirements. This will do that for you. Basically, it is cloning the field, marking it as not multiple and validate each value. It will throw an exception in case of failure.

If you are implementing your own field which could be filled by a "multiple" widget, you need to perform a check on $this->multiple.

Parameters

$value

Returns

array —

Values

widgetAttrs()

widgetAttrs(  $widget) : array

Returns the HTML attributes to add to the field.

Parameters

$widget

Returns

array —

HTML attributes.

httpPost()

httpPost(  $host,   $path,   $data,   $port = 80) : array

Submits an HTTP POST to a reCAPTCHA server

Parameters

$host
$path
$data
$port

Returns

array —

response

qsencode()

qsencode(  $data) : string

Encodes the given data into a query string format

Parameters

$data

Returns

string —

Encoded request

checkAnswer()

checkAnswer(string  $privkey, string  $remoteip, string  $challenge, string  $response, array  $extra_params = array()) : boolean

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

boolean —

success of process