0

Fiddle so far

I'm quite new to jquery and more so to jquery validation plugin. My problem is how to validate multiple forms (the user can add them dynamically) separately/uniquely? I already added different names to the forms, if that is any help?

My second problem is how to $ajax(); to send emails without having to refresh the page.

I'm hoping for a detailed explanation of a solution so I can understand better. Thanks!

user2772219
  • 129
  • 1
  • 10
  • you need to have a server side component to send mail, link it to the ajax call. – run Oct 21 '13 at 05:39
  • well for validation you can go through http://bassistance.de/jquery-plugins/jquery-plugin-validation – bipen Oct 21 '13 at 05:39

1 Answers1

0

You have to include script of validation plugin or use cdn Read http://jqueryvalidation.org/

$("form").each(function() {
    $(this).validate({
        submitHandler: function(form) {
            $.ajax({
                type    : 'POST',
                url     : 'mail.php',// write code to send mail in mail.php
                data    : $(form).serialize(),
                cache   : false,
                dataType: 'text',
                success : function (serverResponse) { 
                      alert('mail sent successfully.'); 
                },
                error   : function (jqXHR, textStatus, errorThrown) {
                      alert('error sending mail');
                }
            });
            return false; // Temporary
        }
    });
});

Demo

Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106
  • How do I validate each form separately? Also, I want to send an email to the user if the validation is a success. Any idea how to do this? – user2772219 Oct 21 '13 at 05:45
  • @user2772219 take a look on my demo first – Rohan Kumar Oct 21 '13 at 05:47
  • It's the same as before? Also, whenever I add a new form, it will only validate the first form. – user2772219 Oct 21 '13 at 05:50
  • For this you can create an `single form` with `multiple form elements`, See this http://stackoverflow.com/questions/18022224/jquery-validation-plugin-doesnt-validate-dynamically-created-form-elements – Rohan Kumar Oct 21 '13 at 06:02