Skip to content

Instantly share code, notes, and snippets.

@jamiewilson
Created October 18, 2017 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jamiewilson/c29186b87c76d7ba740bb7eeb0604138 to your computer and use it in GitHub Desktop.
Save jamiewilson/c29186b87c76d7ba740bb7eeb0604138 to your computer and use it in GitHub Desktop.
Multiple Forms Submit to Google Sheets
<form name="first-form">
<input name="email" type="email" placeholder="Email" required>
<button type="submit">Send</button>
</form>
<form name="second-form">
<input name="email" type="email" placeholder="Email" required>
<button type="submit">Send</button>
</form>
<script>
const firstFormScriptURL = '<FIRST FORM SCRIPT URL>'
const firstForm = document.forms['first-form']
firstForm.addEventListener('submit', e => {
e.preventDefault()
fetch(firstFormScriptURL, { method: 'POST', body: new FormData(firstForm)})
.then(response => console.log('Success!', response))
.catch(error => console.error('Error!', error.message))
})
const secondFormSriptURL = '<SECOND FORM SCRIPT URL>'
const secondForm = document.forms['second-form']
secondForm.addEventListener('submit', e => {
e.preventDefault()
fetch(secondFormSriptURL, { method: 'POST', body: new FormData(secondForm)})
.then(response => console.log('Success!', response))
.catch(error => console.error('Error!', error.message))
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment