Skip to content

Instantly share code, notes, and snippets.

@nola
Created September 22, 2015 16:29
Show Gist options
  • Save nola/c75140a84696c95f1031 to your computer and use it in GitHub Desktop.
Save nola/c75140a84696c95f1031 to your computer and use it in GitHub Desktop.
$('form').validate({ // initialize the plugin
rules: {
email: {
required: true,
email: true
}
},
submitHandler: function (form) {
//alert('valid form submitted'); // for demo
$.ajax({
type: "POST",
url: "util.php",
data: $(form).serialize(),
success: function() {
$('.form-message').html("<div id='message'></div>");
$('#message').html("<h2>Thanks for signing up!</h2>").append("<p>Your information has been submitted. A welcome email is on its way and should arrive shortly.</p>").hide().fadeIn(750, function() {
$('#message');
});
}
});
return false; // for demo
}
});
<script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"></script>
<form action="util.php" method="post">
<br>
<label for="email" >email</label>
<input type="text" name="email" id="email">
<br>
<input id="submit" type="submit" name="submit">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment