Undefined Widget ID when trying to verify response with client-side javascript

616 views
Skip to first unread message

cathel...@gmail.com

unread,
Dec 17, 2014, 7:57:56 PM12/17/14
to reca...@googlegroups.com
Hi--

I am trying to do a very simple test implementation by creating an automatically rendered recaptcha widget, and then verifying the response via client-side javascript when the user clicks a button.

Because I'm using the automatic rendering for a recaptcha widget, I don't bother to get/save the widget ID. According to the documentation, when I try to verify the response with getrecaptcha.getResponse(), the widget ID is optional--if I don't provide one, it will automatically identify the first widget created (I only have one).

But this is not working. When I call the getResponse function, I am expecting a JSON object of the result...but instead, the result is undefined (I get an exception that says the widget ID is invalid).

Has anyone gotten this to work?

Here's my HTML code to automatically render the widget:

    <div class="g-recaptcha" data-sitekey="alongstringofrandomcharacters"></div>

And here's my script to check the response:

      function showValidation() {
        var r;
        r = grecaptcha.getResponse();
        alert(r.success);
      }

Instead of displaying "true" or "false", I get "undefined".



Peter Kakoma

unread,
Feb 9, 2015, 2:35:01 PM2/9/15
to reca...@googlegroups.com
From my tests, grecaptcha.getResponse() merely returns a string. You are trying to access it as though it is something else.
Something like this will work:
        if (!grecaptcha.getResponse()){
            console.log("Select I am not a robot");//Or alert('Select I am not a robot')
        }else{
           console.log(grecaptcha.getResponse()); 
Reply all
Reply to author
Forward
0 new messages