Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Problem with Validating and Ajax Submission

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #24778

    Am having a very silly problem with Ajax Form Submission after validation of the form is complete… when I remove the ajax form submission, the email works fine, but when i do it, it doesn’t :|
    Here is a live example of my form :arrow: Contact Form

    Code:
    $(function() {
    //find all form with class jqtransform and apply the plugin
    $(‘#contactForm’).validate({
    submitHandler: function(form){
    $(form).ajaxSubmit({
    success: function() {
    $(‘#contactForm’).slideUp(1000);
    $(‘#page-wrap’).append(“

    Thanks, message sent successfully!
    We will get back to you as soon as possible.

    “);
    return false;
    }
    });
    }
    });
    });

    The live example works fine and displays a thank you message but the actual email doesn’t go :(

    #58440

    no one? :|

    #58544

    Hello friends,
    I was having some problem in validating and submitting the form via AJAX as mentioned above, hence I got it working by setting the options for the ajaxForm() method. In the ‘beforeSubmit’ option I checked for the validation of the code and in the success option I just printed the thank you message..

    Code:
    $(function() {
    var options = {
    beforeSubmit: function(){
    return $(‘#contactForm’).validate().form();
    },
    success: function(){
    $(‘#contactForm’).slideUp(1000);
    $(‘#page-wrap’).append(“

    Thanks, message sent successfully! We will get back to you as soon as possible.

    “);
    }

    // other available options:
    //url: url // override for form’s ‘action’ attribute
    //type: type // ‘get’ or ‘post’, override for form’s ‘method’ attribute
    //dataType: null // ‘xml’, ‘script’, or ‘json’ (expected server response type)
    //clearForm: true // clear all form fields after successful submit
    //resetForm: true // reset the form after successful submit
    // $.ajax options can be used here too, for example:
    //timeout: 3000
    };
    $(‘#contactForm’).ajaxForm(options);
    $(‘#contactForm’).validate();
    });

    #58555
    Hugo
    Member

    So the problem here is the e-mail not going out? Could you post some PHP?

    #58565

    Hello hugo,
    Well, the php code works just fine, but the problem I was facing was that I was unable to submit the form using AJAX, when I would call it from the call back function of the validation method. Just like Chris did it in one of his form tutorials. But I solved it by setting the options parameter of the ajaxForm() method, and its now working fine :)

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.