G
G
godsplane2020-08-07 17:08:17
JavaScript
godsplane, 2020-08-07 17:08:17

Where is the error when adding google captcha to the form?

Actually a subject. I thought it was done like this. And in Google docs it seems the same, but spam still comes. Do I need to pass something to function(token)?

spoiler
$('#contact-form').on('submit', function (e) {
    e.preventDefault()
    grecaptcha.ready(function () {
      grecaptcha.execute('6LdlI7EZAAAAAL5Q9Rh0ZyAvZWXeEQB--xeqs8Hu', {
        action: 'submit'
      }).then(function (token) {

        $('.e_name').hide();

        $('.e_phone').hide();
        $('.e_sub').hide();
        $('.e_mes').hide();
        var name = $('#name').val();

        var addres = $('#addres').val();
        var message = $('#message').val();
        var phone = $('#phone').val();
        name = jQuery.trim(name);
        phone = jQuery.trim(phone);
        addres = jQuery.trim(addres);
        message = jQuery.trim(message);


        if (name == "") {
          $('.e_name').fadeIn(100);
          $('#name').val(name);
          $('#name').addClass('error');
        } else {
          $('.error').removeClass('error')
        }
        if (phone == "") {
          $('.e_phone').fadeIn(100);
          $('#phone').val(phone);
          $('#phone').addClass('error');
        } else {
          $('.error').removeClass('error')
        }
        if (addres == "") {
          $('.e_sub').fadeIn(100);
          $('#addres').val(addres);
          $('#addres').addClass('error');
        } else {
          $('.error').removeClass('error')
        }
        if (message == "") {
          $('.e_mes').fadeIn(100);
          $('#message').val(message);
          $('#message').addClass('error');
        } else {
          $('.error').removeClass('error')
        }

        // function validateEmail(email) {
        // 	var emailReg = /^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/;
        // 	return emailReg.test(email);
        // }
        // if (!validateEmail(email)) {
        // 	$('.e_email').fadeIn(100);
        // 	$('#email').val(email);
        // } else {


        if (name == "" || phone == "" || addres == "" || message == "") {
          $(this).removeClass('error')
          return
        } else {
          $('#info').html('<span>Отправка</span>');
          $('#info').show(300);
          var formData = new FormData(document.getElementById("contact-form"));



          $.ajax({
            type: "POST",
            enctype: 'multipart/form-data',
            url: "send.php",
            data: formData,
            processData: false,
            contentType: false,
            cache: false,
            success: function (cevap) {
              $('#info').html('<span style="color:#00da25">Сообщение отправлено</span><br />');
              $('.error').removeClass('error');
              setTimeout(() => {
                $('.form-item').val('');
                $('#info').hide();
                $('.pop-up-wrapper').fadeOut(100);
              }, 5000);
            }
          });



          return false;
        }
      });
    });


  })

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SKEPTIC, 2020-08-07
@pro100chel

Is the captcha checked on the server? From what you added to the js code - not hot, not cold.

D
Dimonchik, 2020-08-07
@dimonchik2013

so try spamming yourself, or hire a parser
here from the code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question