【问题标题】:Why reCaptcha v3 send an empry form to the server为什么 reCaptcha v3 向服务器发送一个空表单
【发布时间】:2021-01-17 20:51:09
【问题描述】:

我已将recaptcha v3 包含到我的简单html 表单中,表单提交很好,但在服务器端我发现一个空数组进入收件箱。 这是我的表单代码的复制/粘贴:

<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
     <script>
       function onSubmit(token) {
         document.getElementById("mywebsite_form").submit();
       }
     </script>


<form id="website_form" class="website-form" action="https://webto.mywebsite.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">

<input type=hidden name="oid" value="00D58000000H4Yu">
<input type=hidden name="retURL" value="http://www.mywebsite.com">



  <div class="form-row">
    <div class="form-group col-md-6">
    <label for="first_name">First Name</label>
    <input class="form-control" id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
    </div>
    <div class="form-group col-md-6">
    <label for="last_name">Last Name</label>
    <input  class="form-control" id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
    </div>
  </div>


    <div class="form-row">
        <div class="form-group col-md-6">
            <label for="email">Email</label>
            <input class="form-control" id="email" maxlength="80" name="email" size="20" type="text"/>
        </div>
        
  </div>
      <div class="form-group col-md-12">
        <label for="subject">Subject</label>
        <input class="form-control" id="subject" maxlength="80" name="subject" size="20" type="text"/>
    </div>
    <div class="form-group col-md-12">
        <label for="description">Description</label>
        <textarea class="form-control" name="description"></textarea>
    </div>
  
  
  <button class="g-recaptcha" 
        data-sitekey="mywebsite_key" 
        data-callback='onSubmit' 
        data-action='submit'>Submit</button>
</form> 

我应该添加哪些额外的行以使表单字段到达另一端“服务器”?

【问题讨论】:

    标签: javascript html forms recaptcha-v3


    【解决方案1】:

    您应该在 google 脚本的 url 中包含“reCAPTCHA_site_key”参数

    <script src="https://www.google.com/recaptcha/api.jsrender=reCAPTCHA_site_key"></script>
    

    【讨论】:

    • 是的,某些 id 不是唯一的,因为我在同一个页面中呈现了两次表单,如果解决了该问题并且表单现在发送良好,但某些字段仍然为空。
    • 你能详细描述一下这个问题吗?
    【解决方案2】:

    我发现了问题,表单在同一个页面中呈现了两次,这使得页面中的不是唯一的,所以表单被发送为空。为了解决我只需要渲染表单 html 代码 1 次的问题,现在问题已经解决了。

    非常感谢大家!

    【讨论】:

      猜你喜欢
      • 2016-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多