Last active
February 18, 2020 15:26
-
-
Save leowebguy/f8f252fce0327d899bc2be04dc82ead1 to your computer and use it in GitHub Desktop.
jquery validate + ajax on submitHandler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function submitShare() { | |
$('form[name=share]').submit(); | |
}; | |
$("form[name=share]").validate({ | |
submitHandler: function (form) { | |
var frm = $('[name=share]').serializeArray(); | |
var data = {}; | |
$.each(frm, function(i,v) { | |
data[v.name] = v.value | |
}); | |
data.text = $('#emailText').html(); | |
$.ajax({ | |
type: "POST", | |
url: "../process.php", | |
data: data, | |
success: function(msg){ | |
$('.toggleHide').each(function() { | |
$(this).hide(); | |
}); | |
$('.toggleShow').each(function() { | |
$(this).show(); | |
}); | |
}, | |
dataType: "html" | |
}); | |
}, | |
rules: { | |
yourname: { | |
required: true | |
}, | |
youremail: { | |
required: true, | |
email: true | |
}, | |
friendname: { | |
required: true | |
}, | |
friendemail: { | |
required: true, | |
email: true | |
} | |
}, | |
messages: { | |
yourname: { | |
required: "Name is required." | |
}, | |
youremail: { | |
required: "Email is required.", | |
email: "Enter a valid email." | |
}, | |
friendname: { | |
required: "Friend’s name is required." | |
}, | |
friendemail: { | |
required: "Friend’s email is required.", | |
email: "Enter a valid email." | |
} | |
}, | |
errorPlacement: function(error, element) { | |
error.insertAfter(element); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment