ReCAPTCHA Invisible - permission issue

When using reCaptcha, I had a problem. In code, using AJAX to submit the form. Before sending, I need to check whether the fields are filled or not. If the fields are empty, submit should not occur.

In this case, if the text fields are not filled, it displays a warning.

The problem is that after rejecting an invalid record, the submit button stops working for 2 or 3 minutes, and there is no error given by reCaptcha. After a certain period of time, reCaptcha starts working again and the submit button starts working.

<form id="contact-form" method="post" action="javascript:void(0)">
       <input type="text" placeholder="Name" id="name">
       <input type="text" placeholder="E-Mail" id="email">
       <textarea placeholder="Message" id="message">/textarea>
       <button class="g-recaptcha pull-right" data-sitekey="#your-site-key" data-callback="sendData" type="submit"> SEND <i class="flaticon-origami34"></i> </button>
</form>

Javascripts:

function sendData(){

    console.log('send data - '); // --> works

    //send datas: 

    $("#contact-form").submit();

};

$('#contact-form').on("submit", function() {

console.log('clicked submit'); // --> works

name = $('#name').val().replace(/<|>/g, ""), // prevent xss
    email = $('#email').val().replace(/<|>/g, ""),
    msg = $('#message').val().replace(/<|>/g, "");

if (name == '' || email == '' || msg == '') {

    alert("Please fill all areas !");

} else {

    console.log('captcha response: ' + grecaptcha.getResponse()); // --> captcha response: 

    // ajax to the php file to send the mail
    $.ajax({
        type: "POST",
        url: "SaveContact.php",
        data: "email=" + email + "&name=" + name + "&msg=" + msg + "&g-recaptcha-response=" + grecaptcha.getResponse()
    }).done(function(status) {
        if (status == "ok") {
            // clear the form fields
            $('#name').val('');
            $('#email').val('');
            $('#message').val('');
        }
    });

}});
+4
source share
4 answers

reset recaptcha,

var recaptchaIframe = document.querySelector('.grecaptcha-badge iframe');
recaptchaIframe.src = recaptchaIframe.src;

.

+2

grecaptcha.reset(opt_widget_id);, opt_widget_id recaptcha .

+1

recaptcha script :

var form = grecaptcha.render('idSelector', {
  'sitekey' : 'your_sitekey',
  'callback': callableFunction

}, true)

"form" widget_id, reset, recaptcha

grecaptcha.reset(form); 
0

, - . Google "" "" onSubmit - . - .

0

Source: https://habr.com/ru/post/1667840/


All Articles