Skip to content

Instantly share code, notes, and snippets.

@John2496
Last active December 20, 2015 03:19
Show Gist options
  • Select an option

  • Save John2496/6062562 to your computer and use it in GitHub Desktop.

Select an option

Save John2496/6062562 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript" src="js/additional-methods.min.js"></script>
</head>
<body>
<form>
<div class="field">
<label class="title">Full Name:</label>
<input type="text" name="full_name" class="required" />
</div>
<div class="field">
<label class="title">Email:</label>
<input type="text" name="email" class="required email" />
</div>
<div class="field">
<label class="title">Confirm Email:</label>
<input type="text" name="email_verify" class="required email" equalTo="input[name='email']" />
</div>
<div class="field">
<label class="title">Phone</label>
<input type="text" name="phone" class="required phoneUS" />
</div>
<input type="submit" />
</form>
<script>
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
onFormSubmit = function(form) {
var fields = $(form).serializeObject()
$.ajax({
url: 'submit.php',
data: fields,
success: function(r) {
alert('form submitted');
}
});
}
$('form').validate({
submitHandler: onFormSubmit
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment