1. Go to this page and download the library: Download mikemix/mxrecaptcha 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/ */
mikemix / mxrecaptcha example snippets
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',
]);
}
}
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
];
}
}