Why reCaptcha v3 send an empry form to the server

49 views Asked by At

I have included the recaptcha v3 to my simple html form, the form submit good, but in the server side i find an empty array coming to inbox. Here a copy/paste of my form code:

<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> 

What additional lines should i add to make the form fields arrive to the other side "server"?

2

There are 2 answers

2
Gianluca Lippolis On

you should include the "reCAPTCHA_site_key" parameter in the url of the google script

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

I figure out the problem, the form was rendered twice in the same page wich make the not unique in the page,so the form was sended empty. To resolve that i have to render the form html code only 1 time, the problem is now solved.

Thanks a lot everyone!