Skip to content

Instantly share code, notes, and snippets.

@royce002
Created April 16, 2020 02:41
Show Gist options
  • Save royce002/bb64d7ef322ffb89c7e9ea1ee8929414 to your computer and use it in GitHub Desktop.
Save royce002/bb64d7ef322ffb89c7e9ea1ee8929414 to your computer and use it in GitHub Desktop.
Adding form data to Google Sheets
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
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;
};
var $form = $('#contactForm'),
url = 'https://script.google.com/macros/s/AKfycbyGHGAnjom4IaAsoBBaC3QqUpVaDIcLmM_Uil-k_chH64bDyBk/exec';
function handleResponse(data) {
console.log('Ajax successful');
$('#contactForm').slideUp("fast");
$('#result').slideDown('slow');
}
$('#form-submit').on('click', function(e) {
e.preventDefault();
$('#form-submit').text("Processing Data").attr("disabled", "disabled").css("backgroundColor", "#00548e");
var jqxhr = $.ajax({
url: url,
method: "GET",
dataType: "json",
data: $form.serializeObject(),
success: handleResponse
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment