Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

javascript - Google ReCaptcha 2 auto submit

My users will see a google repcatcha2 (nocaptcha) in a web page. When they solve the captcha (put the tick in the box) the form should be automatically submit.

Is there any way to do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Sure you can do it. In this post I've explained how to insert reCaptcha into a site and to code javascript to verify user and site.

  1. Add a name to your form with reCaptcha: <form method="post" name="myform">

  2. Add document.myform.submit(); code for submitting of the form upon the site verification success event:

    <script type='text/javascript'>    
      var onReturnCallback = function(response) { 
        var url='proxy.php?url=' + 'https://www.google.com/recaptcha/api/siteverify';  
        $.ajax({ 'url' : url, 
                   dataType: 'json',
                   data: { response: response},
                   success: function( data  ) {  
                        var res = data.success.toString(); 
                        if (res)
                           { document.myform.submit(); }    
                    }  // end success 
               });  // end $.ajax
    
      };  // end onReturnCallback
    </script>
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...