dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: recaptcha invisible ajax + jquery validation

  1. #1
    Join Date
    Aug 2017
    Posts
    4

    Question recaptcha invisible ajax + jquery validation

    Hello guys
    I added recaptcha to my jquery validation. But neither validation nor captcha work now. I can send blank from.
    As I understand I should check captcha (result) inside success function? Tried but can't do it correctly. Maybe I should do smth more and youcan give some pieces of advice. Thanks a lot


    Code:
    jQuery(document).ready(function($) {
        $('.myform').submit(function() {
            var formInputs = $(this).find('.validate');
            var errors = '';
                $(formInputs).each(function() {
                if($.trim(this.value) == '') {
                    fieldLabel = $(this).parent().find('span.label-text').html();
                    errors += '- ' + fieldLabel + '\n'; }
            $.ajax({
           type: "POST",
           url: "/reCaptcha.php",
           data: form.serialize(),
           dataType: "json", 
           error:function(){
               grecaptcha.reset(); },
           success:function(result){
             if(errors.length > 0) {
                alert('You didn't fill:\n\n' + errors);
                return false;
             }else{  $('.submit-button').val('Sending');
                     $('.submit-button').attr('disabled', 'disabled');
                return true;         
             } 
            } 
    });
    reCaptcha.php
    PHP Code:
      jQuery(document).ready(function($) {
        $(
    '.myform').submit(function() {
            var 
    formInputs = $(this).find('.validate');
            var 
    errors '';
                $(
    formInputs).each(function() {
                if($.
    trim(this.value) == '') {
                    
    fieldLabel = $(this).parent().find('span.label-text').html();
                    
    errors += '- ' fieldLabel '\n'; }
            $.
    ajax({
           
    type"POST",
           
    url"/reCaptcha.php",
           
    dataform.serialize(),
           
    dataType"json"
           
    error:function(){
               
    grecaptcha.reset(); },
           
    success:function(result){
             if(
    errors.length 0) {
                
    alert('You didn't fill:\n\n' + errors);
                return false;
             }else{  $('
    .submit-button').val('Sending');
                     $('
    .submit-button').attr('disabled', 'disabled');
                return true;         
             } 
            } 

  2. #2
    Join Date
    Jan 2017
    Location
    Coimbatore, India
    Posts
    106
    I think it would be better if you use the validation plugin, and set rules, messages, submithandler, etc. Now do the following

    1. Log into a Google account and register the domain on which you want to install reCAPTCHA.
    2. Paste the following in the HTML where you want the reCAPTCHA to show up. ...
    3. Inside your validation function, add a new rule

  3. #3
    Join Date
    Aug 2017
    Posts
    4
    Thanks. If I could use plugin I would use it. My contact form doesn't support ready plugins. It'll be too hard to change form and make new settings.
    Does my code too incorrect?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles