
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() | |
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
| Pluf_Form_Field_ReCaptcha::clean | ( | $ | value | ) |
Validate some possible input for the field.
| mixed | Value to clean. |
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
| string | Host | |
| string | Path | |
| array | Data | |
| int | port (80 |
| static Pluf_Form_Field_ReCaptcha::qsencode | ( | $ | data | ) | [static] |
Encodes the given data into a query string format
| array | Array of string elements to be encoded |
| 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
| string | $privkey | |
| string | $remoteip | |
| string | $challenge | |
| string | $response | |
| array | $extra_params an array of extra variables to post to the server |
| 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() |