Skip to content

Instantly share code, notes, and snippets.

@sravan-s
Created December 23, 2015 06:28
Show Gist options
  • Save sravan-s/fd8244cb408e8d792224 to your computer and use it in GitHub Desktop.
Save sravan-s/fd8244cb408e8d792224 to your computer and use it in GitHub Desktop.
var AjaxForm = function(formId) {
var form = document.getElementById(formId),
postLoc = Drupal.absoluteUrl(jQuery(form).attr('action')),
submit = jQuery(form).find('[type="submit"]');
submit.click(function(e) {
e.preventDefault();
if(form.validator) {
if(form.validate()) {
jQuery.post(postLoc, jQuery(form).serialize());
}
} else {
jQuery.post(postLoc, jQuery(form).serialize());
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment