![]() |
|
sfReCaptchaPlugin - 1.3.2Integrates reCAPTCHA service in symfony |
|
![]() |
39
users
Sign-in
to change your status |
Integrates reCAPTCHA service in symfony |
| Name | Status | |
|---|---|---|
|
|
lead | moc.liamg <<ta>> oikkarag |
Copyright (c) 2008 Arthur Koziel <arthur@arthurkoziel.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
| Version | License | API | Released |
|---|---|---|---|
| 1.3.2stable | MIT license | 1.3.0stable | 08/04/2010 |
| 1.3.1stable | LGPL license | 1.3.0stable | 07/04/2010 |
| Version | License | API | Released |
|---|---|---|---|
| 1.3.2stable | MIT license | 1.3.0stable | 08/04/2010 |
| 1.3.1stable | LGPL license | 1.3.0stable | 07/04/2010 |
| Version | License | API | Released |
|---|---|---|---|
| 1.1.0stable | MIT license | 1.1.0stable | 09/07/2008 |
| Version | License | API | Released |
|---|---|---|---|
| 1.0.4stable | MIT license | 1.0.0stable | 04/05/2008 |
| 1.0.3stable | MIT license | 1.0.0stable | 02/01/2008 |
| 1.0.2stable | MIT license | 1.0.0stable | 07/10/2007 |
| 1.0.1stable | MIT license | 1.0.0stable | 06/06/2007 |
| 1.0.0stable | MIT license | 1.0.0stable | 27/05/2007 |
The reCAPTCHA project takes unOCRable bits of text and uses people to decipher them via CAPTCHA tests. Answers are verified by juxtaposing deciphered texts with the undeciphered. By implementing reCAPTCHA you are helping digitize books.
The sfReCaptcha plugin integrates the reCAPTCHA service in symfony.
It comes with a custom validator as well as an example module which demonstrates the usage.
For more information on reCAPTCHA visit recaptcha.net.
To install the plugin, navigate to your symfony project root and run:
$ symfony plugin-install http://plugins.symfony-project.com/sfReCaptchaPlugin
In order to use the reCAPTCHA or Mailhide service, you first need to sign up and get an API key. You can do this here for reCAPTCHA and here for Mailhide.
If you're using a name-based virtual host like
http://jobeet, the API key registration will fail because the reCAPTCHA service doesn't identify yourServerNameas a valid URI.
To handle this, simply append a .tld to your ServerName variable (e.g.
ServerName askeet.org).
Insert your API keys in your applications app.yml:
all:
recaptcha:
active: true
publickey: "foo"
privatekey: "bar"
mailhide:
publickey: "foo"
privatekey: "bar"
test:
recaptcha:
active: false
It's important to make recaptcha not active in your test environment. Otherwise, your tests will fail, since reCAPTCHA is not testable.
You can see an example module by enabling recaptcha in your applications settings.yml:
all:
.settings:
enabled_modules: [recaptcha]
and clear your cache afterwards:
$ symfony cc
Now you can see an example of reCAPTCHA by navigating to:
http://foobar.com/frontend_dev.php/recaptcha
or for Mailhide example, to:
http://foobar.com/frontend_dev.php/recaptcha/mailhide
To use reCAPTCHA in your forms, simply extend reCaptchaForm instead of BaseForm:
class myForm extends reCaptchaForm { public function configure() { // your definitions here... parent::configure(); } }
Please pay attention to insert parent::configure() in your form, otherwise
you'll get an error.
Then, you can put in your template, where you want your CAPTCHA widget:
<?php use_helper('recaptcha') ?> [...] <?php if (sfConfig::get('app_recaptcha_active', false)): ?> <?php echo recaptcha_get_html(sfConfig::get('app_recaptcha_publickey'), $form['response']->getError()) ?> <?php endif ?>
If you are using a form bound to an ORM, you should extend reCaptchaPropelForm or reCaptchaDoctrineForm instead of reCaptchaForm.
If you can't modify form extension, you need a bit more work.
Put this code in the configure() method of your form:
// reCaptcha if (sfConfig::get('app_recaptcha_active', false)) { $this->setWidget('response', new sfWidgetFormInput()); $this->validatorSchema->setPostValidator( new sfValidatorSchemaReCaptcha('challenge', 'response') ); $this->validatorSchema->setOption('allow_extra_fields', true); $this->validatorSchema->setOption('filter_extra_fields', false); }
And the following code in your action:
if ($request->isMethod(sfRequest::POST)) { $requestData = $request->getParameter($this->form->getName()); if (sfConfig::get('app_recaptcha_active', false)) { $requestData['challenge'] = $this->getRequestParameter('recaptcha_challenge_field'); $requestData['response'] = $this->getRequestParameter('recaptcha_response_field'); } $this->form->bind($requestData); if ($this->form->isValid()) { // ... } }
Finally, the template is just the same seen above:
<?php use_helper('recaptcha') ?> [...] <?php if (sfConfig::get('app_recaptcha_active', false)): ?> <?php echo recaptcha_get_html(sfConfig::get('app_recaptcha_publickey'), $form['response']->getError()) ?> <?php endif ?>
If you need an output compliant with XHTML strict, you can pass an optional
4th parameter to recaptcha_get_html(), that forces use of object tag
instead of the unsupported iframe:
<?php echo recaptcha_get_html(sfConfig::get('app_recaptcha_publickey'), $form['response']->getError(), false, true) ?>
