Skip to content

Instantly share code, notes, and snippets.

@codemicro
Created September 1, 2020 13:39
Show Gist options
  • Save codemicro/a6492f2daf052dc18cfe42aecf775938 to your computer and use it in GitHub Desktop.
Save codemicro/a6492f2daf052dc18cfe42aecf775938 to your computer and use it in GitHub Desktop.
Formspree hacky thing
const qName = new URLSearchParams(window.location.search).get("name");
const qEmail = new URLSearchParams(window.location.search).get("email");
const qSub = new URLSearchParams(window.location.search).get("_subject");
const qMessage = new URLSearchParams(window.location.search).get("message");
const referrer = document.referrer
console.log(qName)
console.log(qEmail)
console.log(qSub)
console.log(qMessage)
if(referrer.search("formspree") != -1){
// user returning from Formspree
location.replace("https://www.yoursite.com?success=1")
} else {
document.body.innerHTML += `<form id="hackyForm" action="https://formspree.io/[email protected]" method="post"><input type="hidden" name="name" value="${qName}"><input type="hidden" name="email" value="${qEmail}"><input type="hidden" name="_subject" value="${qSub}"><input type="hidden" name="message" value="${qMessage}"></form>`;
document.getElementById("hackyForm").submit();
}
<html>
<body></body>
<!-- to use this, use this page as a form action instead of sending the message directly to formspreee api -->
<script src="emailRedirect.js"></script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment