Skip to content

Instantly share code, notes, and snippets.

@objectivehtml
Created February 23, 2013 16:17
Show Gist options
  • Select an option

  • Save objectivehtml/5020293 to your computer and use it in GitHub Desktop.

Select an option

Save objectivehtml/5020293 to your computer and use it in GitHub Desktop.
$('form').attr('novalidate', 'novalidate').submit(function() {
var $t = $(this);
var fields = $t.find('input, textarea, select');
var $submit = $t.find('[type="submit"]');
// var isValid = fields.isValid(valOptions);
$t.find('.notify').hide();
$submit.addClass('disabled');
// if(isValid) {
var post = {};
fields.each(function() {
post[$(this).attr('name')] = $(this).val();
});
$.post($t.attr('action'), post, function(data) {
$t.find('.inline-error').remove();
if(!data.success) {
$.each(data.field_errors, function(i, error) {
var $obj = $t.find('[name="'+i+'"]');
$obj.parent().addClass('invalid');
$obj.parents('li').append('<p class="inline-error">'+error+'</p>');
});
}
else {
fields.each(function() {
if($(this).attr('type') != 'hidden') {
$(this).val('');
}
});
$t.find('.notify').show();
}
$submit.removeClass('disabled');
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment