Code Monkey home page Code Monkey logo

recaptchabundle's Introduction

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

<?php echo $view['form']->render($form['recaptcha'], array(
    'options' => array(
        'theme' => 'clean',
    ),
), array(), 'RecaptchaBundle:Form:recaptcha_field.html.php') ?>

Or using JavaScript

<div id="recaptcha-container"></div>
<script type="text/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",
            });
        });
    };
</script>

recaptchabundle's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.