2017 © Pedro Peláez
 

library mxrecaptcha

ZF2 Form integration with v2.0 reCaptcha

image

mikemix/mxrecaptcha

ZF2 Form integration with v2.0 reCaptcha

  • Wednesday, September 16, 2015
  • by mikemix
  • Repository
  • 1 Watchers
  • 2 Stars
  • 721 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

mxreCaptcha

Build Status Scrutinizer Code Quality Code Coverage, (*1)

Easy ZF2 form integration with reCaptcha v2.0, (*2)

Installation

  1. Install with Composer php composer.phar require 'mikemix/mxrecaptcha:~1.0' (we follow the rules of Semantic Versioning)
  2. Load the mxreCaptcha module in your config/application.config.php file
  3. Copy the dist config file cp vendor/mikemix/mxrecaptcha/config/mxrecaptcha.local.php.dist config/autoload/mxrecaptcha.local.php and write your private and public key in it
  4. You are ready to go!

Usage

First of all, add the reCaptcha element to your form. Example form class below:, (*3)

namespace App\Form;

use Zend\Form\Form;

class AddForm extends Form
{
    public function init()
    {
        $this->add([
            'name' => 'recaptcha',   // or any name of your choice
            'type' => 'mxreCaptcha', // this is important, use our reCaptcha component
            'options' => [
                'label' => 'Prove you are human',
            ],
        ]);

        // or

        // This element behaves as any other element.
        // Aside from that, you can pass custom grecaptcha.render parameters
        // available at the docs
        // https://developers.google.com/recaptcha/docs/display#render_param
        // by setting widget_options key in the options, for example:

        $this->add([
            'name' => 'recaptcha',
            'type' => 'mxreCaptcha',
            'options' => [
                'label' => 'Prove you are human',
                'widget_options' => [
                    'theme' => 'dark',
                ],
            ],
        ]);

        $this->add([
            'name' => 'submit',
            'type' => 'submit',
        ]);
    }
}

Example controller, (*4)

namespace App\Controller;

use App\Form\AddForm;
use Zend\Mvc\Controller\AbstractActionController;

class FormController extends AbstractActionController
{
    public function indexAction()
    {
        $form = $this->getServiceLocator()->get('FormElementManager')
            ->get(AddForm::class);

        if ($this->request->isPost()) {
            $form->setData($this->request->getPost());

            if ($form->isValid()) {
                $this->flashMessenger()->addSuccessMessage('Success!');
                return $this->redirect()->toRoute('home');
            }
        }

        return [
            'form' => $form
        ];
    }
}

Example view, (*5)

form->prepare();
?>

= $this->form()->openTag($form) ?>
= $this->formCollection($form) ?>
= $this->form()->closeTag() ?>

Localization

By default, Polish translation for localized error messages is available out of the box. To create custom translation for your application, simply copy the pl.po file from the language directory and name it accordingly to match your translator locale setting (for example fr_ca.po). Finally translate error messages and compile this file to *.mo. Put those two files inside the language directory., (*6)

If you are willing to share your translation, please make a pull request., (*7)

Unit tests

This modules comes up with unit tests. phpUnit is required to run the suite:, (*8)

  1. Clone this repository git clone https://github.com/mikemix/mxreCaptcha.git
  2. Navigate to it cd mxreCaptcha
  3. Download composer php -r "readfile('https://getcomposer.org/installer');" | php
  4. Install dependencies php composer.phar update
  5. Run suite phpunit

The Versions

16/09 2015

dev-master

9999999-dev

ZF2 Form integration with v2.0 reCaptcha

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

zf2 zend framework recaptcha zf2 form

10/09 2015

1.2.0

1.2.0.0

ZF2 Form integration with v2.0 reCaptcha

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

zf2 zend framework recaptcha zf2 form

10/09 2015

1.1.1

1.1.1.0

ZF2 Form integration with v2.0 reCaptcha

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

zf2 zend framework recaptcha zf2 form

10/09 2015

1.1.0

1.1.0.0

ZF2 Form integration with v2.0 reCaptcha

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

zf2 zend framework recaptcha zf2 form

10/09 2015

1.0.3

1.0.3.0

ZF2 Form integration with v2.0 reCaptcha

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

zf2 zend framework recaptcha zf2 form

09/09 2015

1.0.2

1.0.2.0

ZF2 Form integration with v2.0 reCaptcha

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

zf2 zend framework recaptcha zf2 form

09/09 2015

1.0.1

1.0.1.0

ZF2 Form integration with v2.0 reCaptcha

  Sources   Download

MIT

The Requires

 

zf2 zend framework recaptcha zf2 form

09/09 2015

1.0

1.0.0.0

ZF2 Form integration with v2.0 reCaptcha

  Sources   Download

MIT

The Requires

 

zf2 zend framework recaptcha zf2 form