PHP code example of jield-webdev / laminas-recaptcha
1. Go to this page and download the library: Download jield-webdev/laminas-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/ */
jield-webdev / laminas-recaptcha example snippets
'form_elements' => [
'factories' => [
Register::class => ConfigAbstractFactory::class,
],
],
UserController::class => [
'FormElementManager'
],
//To properly load the captcha, we need to use the formElementManager to get the form
$form = $this->formElementManager->get(Register::class);
shell
declare(strict_types=1);
namespace Admin\Form\User;
use CirclicalRecaptcha\Form\Element\Recaptcha;
use Contact\Entity\OptIn;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\EntityManager;
use DoctrineORMModule\Form\Element\EntityMultiCheckbox;
use Laminas\Form\Element\Csrf;
use Laminas\Form\Element\Email;
use Laminas\Form\Element\Text;
use Laminas\Form\Form;
use function _;
use function sprintf;
final class Register extends Form
{
public function __construct(private readonly EntityManager $entityManager)
{
parent::__construct();
}
public function init(): void
{
$this->setAttribute('action', '');
$this->add(
[
'name' => 'firstName',
'type' => Text::class,
'options' => [
'label' => _('txt-first-name'),
],
'attributes' => [
'placeholder' => _('txt-give-your-first-name'),
],
]
);
$this->add(
[
'name' => 'lastName',
'type' => Text::class,
'options' => [
'label' => _('txt-last-name'),
],
'attributes' => [
'placeholder' => _('txt-give-your-last-name'),
],
]
);
$this->add(
[
'name' => 'email',
'type' => Email::class,
'options' => [
'label' => _('txt-company-email-address'),
],
'attributes' => [
'placeholder' => _('txt-give-your-company-email-address'),
],
]
);
$this->add(
[
'name' => 'g-recaptcha-response',
'type' => Recaptcha::class,
]
);
$this->add(
[
'name' => 'csrf',
'type' => Csrf::class,
]
);
$this->add(
[
'name' => 'submit',
'type' => 'submit',
'attributes' => [
'class' => 'btn btn-primary',
'value' => _('txt-register'),
],
]
);
}
}