Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Captcha not rendered #232

Open
antoine1003 opened this issue Sep 1, 2019 · 5 comments
Open

Captcha not rendered #232

antoine1003 opened this issue Sep 1, 2019 · 5 comments

Comments

@antoine1003
Copy link

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
Copy link

urkob commented Jan 27, 2020

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
Copy link

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
Copy link
Author

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
Copy link

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

@benjamin-aubry
Copy link

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants