PHP code example of szmnmichalowski / zf2-nocaptcha

1. Go to this page and download the library: Download szmnmichalowski/zf2-nocaptcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

szmnmichalowski / zf2-nocaptcha example snippets


$ php composer.phar update

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

        $options = array(
            'site_key' => 'YOUR_SITE_KEY',
            'secret_key' => 'YOUR_SECRET_KEY',
        );
        
        $captcha = new \NoCaptcha\Captcha\ReCaptcha($options);

        ...
        $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
            )
        ));
        ...

        <div class="form-group">
             echo $this->formlabel($form->get('captcha')); 

        $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);

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