Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
Prepend token value to html form using js

Am trying to add google recaptcha 3 to my html form. Works find when i call it on page load but due to the fact that it expires after 2mins and should be called when ready, am trying to add it to my submit function but don't know where am doing it wrong.

my js code is:

     <script>
                    
                    
  $(document).ready(function () {
    $('.regformsubmit').click(function (e) {
        
        grecaptcha.execute('6LcVzjYcmykey is here', {action: 'validate_captcha'}).then(function(token) {
                // add token to form
                $("#register_form").prepend('<input type="hidden" name="g-recaptcha-response" id="g-recaptcha-response" value="' + token + '">');
        });
              
      var myForm = jQuery( "#register_form" );

  if ( ! myForm[0].checkValidity() )
  {
    // bonk! failed to validate, so return true which lets the
    // browser show native validation messages to the user
    return true;
  }
      e.preventDefault();
      var country = $('#country').val();
      var fname = $('#fname').val();
        var lname = $('#lname').val();
        var emailid = $('#emailid').val();
        var password = $('#password').val();
        var confirm_password = $('#confirm_password').val();
        var phone = $('#phone').val();
        var vcode = $('#vcode').val();
        var upline = $('#upline').val(); 
        var agree_term = $('#agree_term').val(); 
        var cr = $('#g-recaptcha-response').val(); 
      $.ajax
        ({
          type: "POST",
          url: "process-reg.php",
          data: { "country": country,"fname":fname, "lname": lname, "emailid": emailid, "password": password, "confirm_password": confirm_password, "phone": phone, "vcode": vcode, "upline": upline, "agree_term": agree_term, "cr": cr },
          success: function (data) {
            $('#RegResult').html(data);
            $('#register_form')[0].reset();
          }
        });
    });
  });
</script>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!