Created
September 1, 2020 13:39
-
-
Save codemicro/a6492f2daf052dc18cfe42aecf775938 to your computer and use it in GitHub Desktop.
Formspree hacky thing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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