excelwebzone / EWZRecaptchaBundle

This bundle provides easy reCAPTCHA form field for Symfony.
MIT License
396 stars 160 forks source link

Problems with Options form #284

Open rzp-789 opened 2 years ago

rzp-789 commented 2 years ago

i follow the docs

my ewz_recaptcha.yaml :

# See https://github.com/excelwebzone/EWZRecaptchaBundle for full configuration
ewz_recaptcha:
    public_key:  '%env(EWZ_RECAPTCHA_SITE_KEY)%'
    private_key: '%env(EWZ_RECAPTCHA_SECRET)%'

    version: 2
    enabled: true
    api_host: recaptcha.net
    verify_host: true

My form :

<?php

declare(strict_types=1);

namespace App\Form\Extension;

use App\Form\FormHelper;
use Sylius\Bundle\CustomerBundle\Form\Type\CustomerProfileType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType;

class BaseCustomerTypeExtension extends AbstractTypeExtension
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->remove('gender')
            ->add('phoneNumber', TelType::class, [
                'label' => 'app.form.phone',
                'constraints' => $this->getPhoneNumberConstraints(),
            ])
            ->add('isAgreeToReceiveByMail', CheckboxType::class, [
                'label' => 'app.form.mail',
            ])
            ->add('isAgreeToReceiveBySms', CheckboxType::class, [
                'label' => 'app.form.sms',
            ])
            ->add('isAgreeToReceiveByCourier', CheckboxType::class, [
                'label' => 'app.form.courier',
            ])
            ->add('recaptcha', EWZRecaptchaType::class, array(
                'attr' => array(
                    'options' => array(
                        'theme' => 'light',
                        'type'  => 'image',
                        'size'  => 'normal',
                        'defer' => true,
                        'async' => true,
                    )
                )
            ))
        ;
    }

    public static function getExtendedTypes(): iterable
    {
        return [CustomerProfileType::class];
    }

    private function getPhoneNumberConstraints(): array
    {
        return [
            new NotBlank(FormHelper::getDefaultSyliusValidationGroup()),
        ];
    }
}

added on the twig :

{{ form_row(form.recaptcha) }}

Error => error captcha

if you have an idea, i try too for version 3 but the problem is same with an other option