PHP code example of saeven / zf2-circlical-recaptcha
1. Go to this page and download the library: Download saeven/zf2-circlical-recaptcha 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/ */
saeven / zf2-circlical-recaptcha example snippets
return [
'circlical' => [
'recaptcha' => [
'client' => 'yourclientkeygoeshere',
'server' => 'yourserverkeygoeshere',
'bypass' => false,
'default_timeout' => 900,
],
],
];
'bypass' => getenv('SOMEKEY') === 'development'
namespace CirclicalUser\Form;
use Laminas\Form\Element,
Laminas\Captcha,
Laminas\InputFilter,
Laminas\Form\Element\Password,
Laminas\Form\Element\Text,
Laminas\Form\Form,
CirclicalUser\Form\Element\Recaptcha,
Laminas\Form\Element\Button;
class UserForm extends Form
{
const EMAIL = 'email';
public function __construct( $name, $options = array() )
{
parent::__construct( $name, $options );
}
/**
* Construct a registration form, with an AuthenticationFormInterface instance to establish minimum field count
*/
public function init()
{
$this->add([
'name' => 'g-recaptcha-response',
'type' => Recaptcha::class,
'options' => [
'label' => _( "Please complete the challenge below" ),
'no_sitekey' => false,
'no_script' => false,
'language' => 'en', // see https://developers.google.com/recaptcha/docs/language
],
]);
$this->add([
'name' => self::EMAIL,
'type' => self::EMAIL,
'options' => [
'label' => _( 'Email' ),
],
'attributes' => [
'maxlength' => 254,
],
]);
$this->add([
'name' => 'email_confirm',
'type' => self::EMAIL,
'options' => [
'label' => _( "Confirm Email" ),
],
'attributes' => [
'maxlength' => 254,
],
]);
$this->add([
'name' => 'submit',
'type' => Button::class,
'options' => [
'label' => _( "Submit" ),
],
'attributes' => [
'class' => 'btn btn-primary',
'type' => 'submit',
]
]);
}
}
namespace CirclicalUser\InputFilter;
use CirclicalUser\Form\Validator\RecaptchaValidator;
use Doctrine\Common\Persistence\ObjectRepository;
use DoctrineModule\Validator\NoObjectExists;
use Laminas\Filter\StringToLower;
use Laminas\Filter\StringTrim;
use Laminas\InputFilter\InputFilter;
use Laminas\Form\Element;
use Laminas\Captcha;
use CirclicalUser\Form\Filter\ArrayBlock;
use HTMLPurifier;
use Laminas\Validator\EmailAddress;
use Laminas\Validator\StringLength;
class UserInputFilter extends InputFilter implements UserInputFilterInterface
{
const EMAIL = 'email';
const RECAPTCHA = 'g-recaptcha-response';
protected $userRepository;
protected $has_captcha;
public function __construct( ObjectRepository $userRepository, $has_captcha )
{
$this->userRepository = $userRepository;
$this->has_captcha = $has_captcha;
}
public function init()
{
if( $this->has_captcha )
{
$this->add([
'name' => self::RECAPTCHA,
'checked" ),
],
],
[
'name' => NoObjectExists::class,
'options' => [
'fields' => ['email'],
'messages' => [
NoObjectExists::ERROR_OBJECT_FOUND => _( "That email is already taken, please log in instead" ),
],
'object_repository' => $this->userRepository,
],
],
],
]);
$this->add([
'name' => 'email_confirm',
'