2017 © Pedro PelĂĄez
 

library zf2-nocaptcha

No CAPTCHA reCAPTCHA module for Zend Framework 2

image

szmnmichalowski/zf2-nocaptcha

No CAPTCHA reCAPTCHA module for Zend Framework 2

  • Saturday, March 25, 2017
  • by szmnmichalowski
  • Repository
  • 2 Watchers
  • 6 Stars
  • 902 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 3 Open issues
  • 2 Versions
  • 4 % Grown

The README.md

NoCaptcha

Software License Build Status, (*1)

NoCaptcha is a Zend Framework 2 module which is integrated with new version of Google reCAPTCHA.br/ More info about "No CAPTCHA reCAPTCHA", (*2)

Installation

You can install this module by cloning this project into your ./vendor/ directory, or using composer, which is more recommended:br/ 1. Add this project into your composer.json, (*3)

"require": {
    "szmnmichalowski/zf2-nocaptcha": "dev-master"
}

2. Update your dependencies, (*4)

$ php composer.phar update

3. Add module to your application.config.php, (*5)

return array(
    'modules' => array(
        'Application',
        'NoCaptcha' // <- Add this line
    )
);

Usage

1. Add to layout.phtml in head section:, (*6)

<script src="https://www.google.com/recaptcha/api.js" async defer></script>

2. Register your site at https://www.google.com/recaptcha/admin#createsite.br/ After you register your site you will get: - Site key - Secret key, (*7)

Without this two keys, module won't work correctly, (*8)

3. Pass these keys to \NoCaptcha\Captcha\ReCaptcha class, (*9)

Example #1: Basic, (*10)

        $options = array(
            'site_key' => 'YOUR_SITE_KEY',
            'secret_key' => 'YOUR_SECRET_KEY',
        );

        $captcha = new \NoCaptcha\Captcha\ReCaptcha($options);

In your form class:, (*11)

        ...
        $this->add(array(
            'type'  => 'Zend\Form\Element\Captcha',
            'name' => 'captcha',
            'attributes' => array(
                'id' => 'recaptcha-response',
            ),
            'options' => array(
                'label' => 'Are you a bot?',
                'captcha' => $captcha // <-- Object of NoCaptcha\Captcha\ReCaptcha
            )
        ));
        ...

Last step is to render captcha input in your view:, (*12)

        <div class="form-group">
            <?php echo $this->formlabel($form->get('captcha')); ?>
            <div>
                <?php echo $this->formCaptcha($form->get('captcha')); ?>
                <div class="error-message">
                    <?php echo $this->formElementErrors($form->get('captcha')); ?>
                </div>
            </div>
        </div>

Example #2: Advanced, (*13)

        $options = array(
            'site_key' => 'YOUR_SITE_KEY',
            'secret_key' => 'YOUR_SECRET_KEY',
            'theme' => 'dark',
            'type' => 'image',
            'size' => 'normal',
            'messages' => array(
                'errCaptcha' => 'Custom message when google API return false'
            ),
            'service_options' => array(
                'adapter' => 'Zend\Http\Client\Adapter\Curl', // override default HttpClient adapter options
            )
        );

        $captcha = new \NoCaptcha\Captcha\Recaptcha($options);

Or you can use setters, (*14)

        $captcha->setSiteKey($siteKey);
        $captcha->setSecretKey($secretKey);
        $captcha->setTheme('dark');
        $captcha->setType('image');
        $captcha->setSize('normal');

NoCaptcha uses Zend\Http\Client to verify if captcha is valid. If for some reasons you want to pass additional settings to Client class, you can do this by:, (*15)

$service = $captcha->getService();
$service->setOptions(array(
  'sslverifypeer' => false
));

reCAPTCHA options

Theme:br/ - light (default) - dark, (*16)

Type: br/ - image (default) - audio, (*17)

Size: br/ - normal (default) - compact, (*18)

More information about options you can find at https://developers.google.com/recaptcha/docs/display, (*19)

The Versions

25/03 2017

dev-master

9999999-dev https://github.com/szmnmichalowski/ZF2-NoCaptcha

No CAPTCHA reCAPTCHA module for Zend Framework 2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Szymon MichaƂowski

zf2 zend captcha module recaptcha

25/03 2017

1.0.0

1.0.0.0 https://github.com/szmnmichalowski/ZF2-NoCaptcha

No CAPTCHA reCAPTCHA module for Zend Framework 2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Szymon MichaƂowski

zf2 zend captcha module recaptcha