1
0
forked from jason/scj

form submission

This commit is contained in:
Jason Stedwell
2026-06-30 22:49:30 -05:00
parent 7593fb46cf
commit cf9f9c5f1a
4 changed files with 21 additions and 11 deletions
+18 -9
View File
@@ -18,7 +18,7 @@
back to mailto only if the request fails.
---------------------------------------------------------- */
var CONTACT_EMAIL = 'stormcloudjumpers@gmail.com';
var FORM_ENDPOINT = ''; // e.g. 'https://script.google.com/macros/s/XXXX/exec'
var FORM_ENDPOINT = 'https://script.google.com/macros/s/AKfycbzwcGznA_bTggaE1xxqNh0DY0yBJnDJ5ZbZp8uw4lVcYWaxvfZorKAHgNw0hdzxtWljOA/exec';
var $ = function (s, c) { return (c || document).querySelector(s); };
var $$ = function (s, c) { return Array.prototype.slice.call((c || document).querySelectorAll(s)); };
@@ -116,17 +116,26 @@
};
if (FORM_ENDPOINT) {
// Progressive enhancement: POST to Google Apps Script (sends via Gmail).
var body = new URLSearchParams(data).toString();
// Progressive enhancement: POST to Google Apps Script (sends via her Gmail).
// Apps Script web apps don't send CORS headers, so we use no-cors and
// treat a resolved request as success (the opaque response can't be read).
// A genuine network failure rejects and falls back to mailto.
var btn = form.querySelector('button[type="submit"]');
if (btn) { btn.disabled = true; btn.textContent = 'Sending…'; }
fetch(FORM_ENDPOINT, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: body
}).then(function (r) {
if (!r.ok) throw new Error('bad status');
if (ok) { ok.textContent = 'Thanks! Your inquiry has been sent — well reply within a day or two.'; ok.hidden = false; }
mode: 'no-cors',
body: new URLSearchParams(data)
}).then(function () {
if (ok) {
ok.className = 'form__msg form__msg--ok';
ok.textContent = 'Thanks! Your inquiry has been sent — well reply within a day or two.';
ok.hidden = false;
}
form.reset();
}).catch(finishMailto);
}).catch(finishMailto).then(function () {
if (btn) { btn.disabled = false; btn.textContent = 'Send Inquiry'; }
});
} else {
finishMailto();
}