Search code examples
javascriptjquerythemesrecaptchagetscript

ReCAPTCHA ajax loaded theme problem


Can not figure out how to theme an ajax loaded recaptcha. The below code does not work.
From Google Recaptcha

Saw this post Recaptcha ajax API custom theme not working, but I am definitely viewing in localhost and recaptcha is working fine, just not changing themes.

Anyone have advice on how to get the white theme to work?

    <script type='text/javascript'>
        var RecaptchaOptions = {
            theme : 'white'
         };
    </script>
    <div id="recaptcha_content">
      <noscript>
        <iframe src="http://www.google.com/recaptcha/api/noscript?k=6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q" height="300" width="500" frameborder="0"></iframe><br />
        <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
        <input type='hidden' name='recaptcha_response_field' value='manual_challenge' />
      </noscript>
    </div>
    <script type="text/javascript">
    $(document).ready(function() {
        $.getScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js',
            function() {Recaptcha.create("6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q", "recaptcha_content");
        });

    });
    </script>

Solution

  • I't doesn't look like you are adding your options that you have set RecapthcaOptions. Try changing to:

    $.getScript('http://www.google.com/recaptcha/api/js/recaptcha_ajax.js',
            function() {Recaptcha.create("6Ldr7woAAAAAADa_69Mr-EZKAeYyEx9N08q", "recaptcha_content", RecaptchaOptions);
    });
    

    See the doc's, the third option passed to the .create() method is the options. You are setting up a variable outside the function to set the options, but don't include them.