Skip to content

Instantly share code, notes, and snippets.

@robjcordes
Created September 27, 2012 21:33
Show Gist options
  • Save robjcordes/3796596 to your computer and use it in GitHub Desktop.
Save robjcordes/3796596 to your computer and use it in GitHub Desktop.
$(document).ready(function(){
idonate.loadForm('.form-container');
});
idonate = {
postNode : function(){
},
serialize : 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;
},
loadForm : function(div){
$(div).load('/sites/all/modules/idonate_custom/services-demo-form.html', function(){
$('form#services-demo').submit(function() {
$('#result').text(JSON.stringify($('form#services-demo').serializeObject()));
console.log('submit');
return false;
});
});
}
}
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
console.log(this);
$.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;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment