Git Product home page Git Product logo

googlerecaptchabundle's Introduction

GoogleReCaptchaBundle

ReCAPTCHA is a free CAPTCHA service that protects websites from spam and abuse. This bundle uses the GoogleReCaptcha library or validating a users "No CAPTCHA reCAPTCHA" response and provides a custom form type, a custom validation constraint as well as a validator to use with the Symfony Form Component.

Latest Stable Version Latest Unstable Version License

Installation

The recommended way to install GoogleReCaptchaBundle is through Composer.

# Install Composer
curl -sS https://getcomposer.org/installer | php

Next, run the Composer command to install the latest stable version of GoogleReCaptcha:

composer require "nietonfir/google-recaptcha-bundle"

Or add GoogleReCaptchaBundle in your composer.json

"require": {
    "nietonfir/google-recaptcha-bundle": "dev-master"
}

and tell Composer to install the library:

composer update "nietonfir/google-recaptcha-bundle"

After installing, don't forget to enable the bundle:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Nietonfir\Google\ReCaptchaBundle\NietonfirGoogleReCaptchaBundle(),
    );
}

Configuration

Add the following configuration to your config.yml.

nietonfir_google_recaptcha:
    sitekey: <your_site_key_here>
    secret: <and_your_secret_here>
    validation:
        form_name: <your_form_name>
        field_name: recaptcha

Additionally you have to add the corresponding form field themes depending on your used templating engine in config.yml.

# Twig
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"
    form_themes:
        - 'NietonfirGoogleReCaptchaBundle:Form:fields.html.twig'

# PHP
framework:
    templating:
        form:
            resources:
                - 'NietonfirGoogleReCaptchaBundle:Form'

Usage

Using the Bundle is dead simple:

  1. Create your form type as usual

  2. Add a field using the recaptcha field type

    $builder->add('recaptcha', 'recaptcha');
    
  3. Make your controller implement ReCaptchaValidationInterface

    use Nietonfir\Google\ReCaptchaBundle\Controller\ReCaptchaValidationInterface;
    
    class DefaultController extends Controller implements ReCaptchaValidationInterface
    
  4. โ€ฆ

  5. Profit!

Now when form->isValid() is called, the submitted reCAPTCHA response is validated against the Google API. Be advised that both the form and the field name used have to be set in config.yml.

TODOs

  • Add some info() to the form & field name config values in Configuration.php
  • Translate the error messages returned form the Google API to something more meaningful
  • Update documentation
  • Add some more examples
  • Add missing unit tests

googlerecaptchabundle's People

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.