EWZRecaptchaBundle icon indicating copy to clipboard operation
EWZRecaptchaBundle copied to clipboard

Captcha not rendered

Open antoine1003 opened this issue 6 years ago • 5 comments

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?

antoine1003 avatar Sep 01 '19 20:09 antoine1003

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.

urkob avatar Jan 27 '20 16:01 urkob

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

benjamin-aubry avatar Apr 14 '22 09:04 benjamin-aubry

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 😃

antoine1003 avatar Apr 14 '22 09:04 antoine1003

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

benjamin-aubry avatar Apr 14 '22 09:04 benjamin-aubry

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 !

benjamin-aubry avatar Apr 14 '22 12:04 benjamin-aubry