2017 © Pedro Peláez
 

library zend-service-recaptcha-v2

Zend Framework 3 service for Google ReCaptcha v2

image

xorock/zend-service-recaptcha-v2

Zend Framework 3 service for Google ReCaptcha v2

  • Saturday, January 28, 2017
  • by xorock
  • Repository
  • 1 Watchers
  • 2 Stars
  • 365 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 4 Versions
  • 23 % Grown

The README.md

Zend Framework 3 integration with Google ReCaptcha v2

Provides Google ReCaptcha v2 integration for Zend Framework 3., (*1)

Installation

Install this library using composer:, (*2)

$ composer require xorock/zend-service-recaptcha-v2

Then add ZfServiceReCaptcha2 to Your module config under the modules key., (*3)

Using Zend Framework Captcha element

use Zend\Form\Element\Captcha;
use ZfServiceReCaptcha2\Captcha\ReCaptcha2;

$this->add([
    'type'       => Captcha::class,
    'name'       => 'g-recaptcha-response', // name is required for element to be validated
    'options'    => [
        'label' => 'Please answer question',
        'captcha' => [
            'class' => ReCaptcha2::class,
            'options' => [
                'hl' => 'en', // english is set by deafult, this line is not required
                'theme' => 'light', // see options below
                'callback' => '', // callback function, etc.
                'public_key'  => 'Generated public key',
                'private_key' => 'Generated private key'
            ],
        ],
    ],
]);

Options

Form element allows two different type of options: params and attributes. Both refer to https://developers.google.com/recaptcha/docs/display configuration options. Parameters are published inside 'script' tag, while the attributes referes to 'div.g-recaptcha element'. By default they are defined as:, (*4)

/**
 * Parameters for the script object
 *
 * @var array
 */
protected $params = array(
    'onload' => null,
    'render' => 'onload',
    'hl'     => 'en'
);

/**
 * Attributes for div element
 *
 * @var array
 */
protected $attributes = array(
    'class'            => 'g-recaptcha',
    'theme'            => 'light',
    'type'             => 'image',
    'tabindex'         => 0,
    'callback'         => null,
    'expired-callback' => null
);

ReCaptcha2 form element

ZfServiceReCaptcha2 component also comes with a predefined element ReCaptcha2, which extends built-in \Zend\Form\Element\Captcha. By default, it consumes following config:, (*5)

return [
    'zfservicerecaptcha2' => [
        'recaptcha' => [
            'options' => [
                // Captcha options
                'hl' => 'en',
                'public_key'  => 'Generated public key',
                'private_key' => 'Generated private key'
            ],
        ]
    ]
];

It is convenient to set Your ReCaptcha keys and other options in general application configuration. You can use this element by simply defining, (*6)

use ZfServiceReCaptcha2\Form\Element\ReCaptcha2;

$this->add([
    'type'       => ReCaptcha2::class,
    // Field name is defined by factory
    // 'name'       => 'g-recaptcha-response', 
    'options'    => [
        'label' => 'Please answer question',
    ],
]);

The Versions

28/01 2017

dev-master

9999999-dev

Zend Framework 3 service for Google ReCaptcha v2

  Sources   Download

BSD-3-Clause

The Requires

 

form http zend captcha zf3 recaptcha

05/11 2016

0.1.0

0.1.0.0

Zend Framework 3 service for Google ReCaptcha v2

  Sources   Download

BSD-3-Clause

The Requires

 

form http zend captcha zf3 recaptcha

04/11 2016

0.0.2

0.0.2.0

Zend Framework 3 service for Google ReCaptcha v2

  Sources   Download

BSD-3-Clause

The Requires

 

form http zend captcha zf3 recaptcha

04/11 2016

0.0.1

0.0.1.0

Zend Framework 3 service for Google ReCaptcha v2

  Sources   Download

BSD-3-Clause

The Requires

 

form http zend captcha zf3 recaptcha