google recaptcha发送电子邮件

时间:2016-07-22 03:38:46

标签: javascript html captcha html-form

我希望使用google的recaptcha添加到我的网站。如果recaptcha将true返回到发送按钮,则html表单只需调用MAILTO操作。这是<head><body>

中的简化代码
<head>
    <script type="text/javascript">
      var onloadCallback = function() {
        grecaptcha.render('html_element', {
          'sitekey' : 'my key'
        });
      };
    </script>
    <script src='https://www.google.com/recaptcha/api.js'></script>
</head>

<body>
    <form action="MAILTO:my.email@example.com" method="post" enctype="text/plain">
        Name<br><input type="text"><br><br>
        E-mail<br><input type="text"><br><br> 
        <input type="submit" value="Send">
        <input type="reset" value="Reset">
        <div class="g-recaptcha" data-sitekey="mykey"></div>
    </form>

    <script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
    async defer>
    </script>
</body>

一个问题是我是javascript的新手,所以正确地遵循google's javascript API一直很困难。可以随时按下send按钮。

简而言之,我想学的是:

  1. 当google的验证码返回true时,如何仅允许发送按钮运行。
  2. 如何在css中居中验证码。

1 个答案:

答案 0 :(得分:0)

 <script type="text/javascript">
var verifyCallback = function(response) {
//called when success
 document.all.body.hide.style.display="block";
};
var onloadCallback = function(){
grecaptcha.render('verify', {
'sitekey' : 'your_site_key',
'callback' : verifyCallback,
'theme' : 'dark'
});
};
</script>
</head>
<body>
<div id="verify"></div>
<form>
<button type="submit" id="hide">Submit</button>
</form>
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer>
</script>
<style>#hide{display:none;}</style> </body></html>