Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用google recaptcha v2在html和node.js应用程序中验证表单提交_Javascript_Html_Node.js - Fatal编程技术网

Javascript 如何使用google recaptcha v2在html和node.js应用程序中验证表单提交

Javascript 如何使用google recaptcha v2在html和node.js应用程序中验证表单提交,javascript,html,node.js,Javascript,Html,Node.js,我有一个通讯注册表,我想包括一个recaptcha验证。我已经根据自动显示文档添加了小部件,没有问题。但是,我不知道如何在服务器端验证验证码,我该如何处理密钥?如何调用g-recaptcha-response标签?以下是我表格的代码: <form class="form-signin" action="/newsletter" method="post"> <input type="text"

我有一个通讯注册表,我想包括一个recaptcha验证。我已经根据自动显示文档添加了小部件,没有问题。但是,我不知道如何在服务器端验证验证码,我该如何处理密钥?如何调用g-recaptcha-response标签?以下是我表格的代码:

<form class="form-signin" action="/newsletter" method="post">
  <input type="text" name="firstName" class="form-control top-form" placeholder="First Name" required autofocus>
  <input type="text" name="lastName" class="form-control middle-form" placeholder="Last Name" required>
  <input type="email" name="email" class="form-control middle-form" placeholder="Email" required>
  <input type="text" name="companyName" class="form-control bottom-form" placeholder="Company Name (if applicable)">
  <div id="label-textarea">
    <label for="message-textarea">Tell Me About Your Business:</label>
  </div>

  <textarea name="messageContent" class="form-control" rows="8" cols="80" placeholder="Include any relevant contact information that you want to display on your card (websites, social media, etc...)"></textarea>
  <div class="g-recaptcha" data-callback="recaptcha_callback" data-sitekey="6LdeRNkZAAAAAPn4PlriZzUeMsPsoOoGtcF2NeuW"></div>
  <button class="btn btn-lg btn-dark btn-block" type="submit">Claim Your Card!</button>
</form>

告诉我你的生意:
认领你的卡!

我知道你应该有一个回调函数,但我不知道它应该包括什么。文档说您需要使用密钥和响应参数向api发出post请求,但我不知道如何做到这一点。如果有人能告诉我如何正确地集成GoogleReCAPTCHA,我将不胜感激

所以根据谷歌文档。当您的用户将完成recaptcha挑战并通过测试时。然后,在服务器上获得的表单witch上,将通过post参数发送“响应”,然后使用方法post调用并发送字段:您的秘密id和响应代码witch to::

URL: https://www.google.com/recaptcha/api/siteverify METHOD: POST
您将返回json:

{
  "success": true|false,
  "challenge_ts": timestamp,  // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
  "hostname": string,         // the hostname of the site where the reCAPTCHA was solved
  "error-codes": [...]        // optional
}