PHP code example of excelwebzone / recaptcha-bundle
1. Go to this page and download the library: Download excelwebzone/recaptcha-bundle 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/ */
excelwebzone / recaptcha-bundle example snippets
// in AppKernel::registerBundles()
$bundles = array(
// ...
new EWZ\Bundle\RecaptchaBundle\EWZRecaptchaBundle(),
// ...
);
php
public function buildForm(FormBuilder $builder, array $options)
{
// ...
$builder->add('recaptcha', EWZRecaptchaType::class, array(
'attr' => array(
'options' => array(
'theme' => 'light',
'type' => 'image',
'size' => 'invisible', // set size to invisible
'defer' => true,
'async' => true,
'callback' => 'onReCaptchaSuccess', // callback will be set by default if not defined (along with JS function that validate the form on success)
'bind' => 'btn_submit', // this is the id of the form submit button
// ...
)
)
));
// ...
}
php
namespace MyNamespace\DependencyInjection;
use MyNamespace\Form\ContactType;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Extension\Extension;
class ContactFormExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$container->register(ContactType::class)
->addArgument(new Reference('ewz_recaptcha.ContactRecaptchaService'))
->addTag('form.type');
}
}
// ...
php
namespace MyNamespace\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class ContactType extends AbstractType
{
/** @var FormBuilderInterface */
private $recaptcha;
public function __construct(?FormBuilderInterface $recaptcha)
{
$this->recaptcha = $recaptcha;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
// ...
if(null !== $this->recaptcha) {
$builder->add($this->recaptcha);
}
// ...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.