genemu / GenemuFormBundle

Extra Form : Captcha GD, Tinymce, Recaptcha, JQueryDate, JQueryAutocomplete, JQuerySlider, JQueryFile, JQueryImage
587 stars 265 forks source link

Support for display reCAPTCHA from AJAX API #362

Closed reypm closed 7 years ago

reypm commented 9 years ago

I'm just wondering, since I didn't see nothing at config level, if this bundle supports for display reCAPTCHA from AJAX API as explained here if it's supported any example around configuration to take care?

WedgeSama commented 9 years ago

You are right. The bundle does not handle reCaptcha loading by js (so by definition, ajax too). I made a pull request to fix this bug.

You can use this genemu_recaptcha_javascript block in a custom template form file until the pull request will be merge.

{% block genemu_recaptcha_javascript %}
{% spaceless %}
    <script type="text/javascript" src="{{ asset("https://www.google.com/recaptcha/api/js/recaptcha_ajax.js") }}"></script>
    <script type="text/javascript">
        function genemu_recaptcha_load()
        {
            Recaptcha.create('{{ public_key }}', '{{ id }}_div', {{ configs|json_encode|raw }});
        }

        if (window.addEventListener) {
            window.addEventListener('load', genemu_recaptcha_load, false);
        } else if (window.attachEvent) {
            window.attachEvent('onload', genemu_recaptcha_load);
        } else {
            window.onload = genemu_recaptcha_load;
        }
    </script>
{% endspaceless %}
{% endblock genemu_recaptcha_javascript %}
emimarz commented 7 years ago

Sorry for my ignorance, that code give me an error Variable "public_key" does not exist in blablabla.html.twig in line where this is Recaptcha.create('{{ public_key }}', '{{ id }}_div', {{ configs|json_encode|raw }});

how can I fix that?