Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcw/recaptchabundle
Integrate the reCaprtcha Bundle into your Symfony2 application
https://github.com/marcw/recaptchabundle
Last synced: 2 months ago
JSON representation
Integrate the reCaprtcha Bundle into your Symfony2 application
- Host: GitHub
- URL: https://github.com/marcw/recaptchabundle
- Owner: marcw
- Created: 2011-03-01T16:18:46.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2011-03-07T14:55:55.000Z (almost 14 years ago)
- Last Synced: 2024-10-11T13:12:15.643Z (3 months ago)
- Language: PHP
- Homepage:
- Size: 854 KB
- Stars: 2
- Watchers: 2
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Provides use reCAPTCHA as form field.
Installation
============**Add RecaptchaBundle to your src/Bundle dir**
You can download it from here http://excelwebzone.github.com/RecaptchaBundle
**Add RecaptchaBundle to your application kernel:**
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new EWZ\RecaptchaBundle\EWZRecaptchaBundle(),
// ...
);
}**Add the EWZ namespace to your autoloader:**
// app/autoload.php
$loader->registerNamespaces(array(
...
'EWZ' => __DIR__.'/../src',
));**Add your private and public key for reCAPTCHA in configuration file:**
If you use secure url for reCAPTCHA put true in secure.
// app/config/config.yml
framework:
...
validation:
enabled: true
annotations:
namespaces:
recaptcha: EWZ\RecaptchaBundle\Validator\Constraints\...
ewz_recaptcha:
pubkey: here_is_your_publick_key
privkey: here_is_your_private_key
secure: true
Use in forms
------------In your form class add following lines
use use EWZ\RecaptchaBundle\Form\RecaptchaField;
When you create form (if you create it in separated class not in the controller)
you need pass container into the method that preparing form.Let's see how it works.
In the controller we have some action. In this action we try to create the form.
public function someAction(){
...
$form = new RegisterForm('register');
// init values
$form->get('recaptcha')->setScriptURLs($this->container);
...
}In the Register form class
protected function configure()
{
...
$this->add(new RecaptchaField('recaptcha'));
...
}Use in view
-----------In template add following lines
render($form['recaptcha'], array(
'options' => array(
'theme' => 'clean',
),
), array(), 'RecaptchaBundle:Form:recaptcha_field.html.php') ?>Or using JavaScript
window.onload = function () {
$.getScript("<?php echo $form['recaptcha']::RECAPTCHA_API_JS_SERVER ?>", function() {
Recaptcha.create("<?php echo $form['recaptcha']->getPublicKey() ?>", "recaptcha-container", {
theme: "clean",
});
});
};