excelwebzone / EWZRecaptchaBundle

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

Captcha not rendered #232

Open antoine1003 opened 5 years ago

antoine1003 commented 5 years ago

Hi,

I installed this pluggin follow all steps but when I add the line : ->add('recaptcha', EWZRecaptchaType::class) the form id not rendered.

Here is aa photo of the bottom of my form : Form

The html of the field is :

<label for="number_recaptcha" class="required">Recaptcha</label>

Do you have any idea of what is happening?

urkob commented 4 years ago

Hi antoine1003

When you install the bundle and also the recipe, you have a custom one in config/packages/dev/wez_recaptcha.yaml.

In this the captcha is disabled (enabled: false).

Set it to enabled: true and you will see it in the form.

benjamin-aubry commented 2 years ago

Same issue here with symfony 5.4. The label is displayed but nothing else. It is not related to the enabled parameter.

Something is strange because it is working well on another project with the same symfony version.

@antoine1003 do you remember how did you solve this old problem ?

Thx

antoine1003 commented 2 years ago

Hey @benjamin-aubry , Unfortunatly I couldn't solve this problem... So I removed this package and added manualy a recaptcha in the form template

<!-- Sample of my form -->
<div class="form-group">
     {{ form_row(form.body) }}
</div>
<div class="form-group">
    <div name="captcha" class="g-recaptcha" data-sitekey="{{ captcha_public }}"></div>
</div>

<!-- [...] -->
{% block javascript %}
    <script src='https://www.google.com/recaptcha/api.js'></script>
{% endblock %}

The captcha_public is set in my config/services.yaml :

captcha_public: 'my-google-key'

and in the config/packages/twig

twig:
   globals:
      captcha_public: '%captcha_public%'

And use google/recaptcha package to check in in my controller :

if ($form->isSubmitted() && $form->isValid()) {
    $recaptcha = new ReCaptcha($params->get('captcha_secret'));
    $resp = $recaptcha->verify($request->request->get('g-recaptcha-response'), $request->getClientIp());
    $contact = $form->getData();
    $nbError = 0;
    if (!$resp->isSuccess()) {
        $message = $translator->trans('error.bad_captcha');
        // Do something if the submit wasn't valid ! Use the message to show something
        $this->addFlash('error', $message);
        $nbError ++;
    }
    // ...
}

I don't know if it helps but thats how I handled it 😃

benjamin-aubry commented 2 years ago

Thx ! I let you know if I find what the problem is.

benjamin-aubry commented 2 years ago

Finallly in my case it was a config issue, I didn't notice that there is 2 config files so the solution given by @urkob worked.

Thx !