Last active
July 4, 2024 16:22
-
-
Save msteele3/9c98c9e2203e5e1f6dbb2bfbb246df6f to your computer and use it in GitHub Desktop.
Free Waitlist Using Google Sheets
This file contains hidden or 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
| APPSCRIPT CODE(Adapted, see bottom for source): | |
| const sheets = SpreadsheetApp.openByUrl("YOURSHEETLINKHERE") | |
| const sheet = sheets.getSheetByName("Sheet1"); | |
| function doPost(e){ | |
| let data = e.parameter; | |
| sheet.appendRow([data.Email]); | |
| return ContentService.createTextOutput("Your message was successfully sent to the Googlesheet database!"); | |
| } | |
| Consts and submit code: | |
| const googleEndpoint = | |
| "https://script.google.com/macros/s/YOURMACRODEPLOYMENT HERE/exec"; | |
| const [email, setEmail] = useState(""); | |
| const [submitted, setSubmitted] = useState(false); | |
| const handleSubmit = (event: React.FormEvent) => { | |
| const form = event.target as HTMLFormElement; | |
| event.preventDefault(); | |
| const formData = new FormData(form); | |
| console.log(formData); | |
| console.log(email); | |
| fetch(googleEndpoint, { | |
| method: "POST", | |
| body: formData, | |
| }); | |
| setEmail(""); | |
| setSubmitted(true); | |
| }; | |
| FORM CODE: | |
| <form | |
| className="flex" | |
| onSubmit={(e) => { | |
| handleSubmit(e); | |
| }} | |
| > | |
| <input | |
| type="email" | |
| name="Email" | |
| placeholder={placeholder} | |
| value={email} | |
| onChange={handleChange} | |
| /> | |
| <button | |
| type="submit" | |
| > | |
| {buttonText} | |
| </button> | |
| </form> | |
| Credit: | |
| Shoutout Anatu Tech for the appscript tutorial(that is what this code is adapted from), | |
| if you guys are looking for full stack tutorials his look pretty sick | |
| His video showcasing how to do this with react and more data in the form: https://www.youtube.com/watch?v=ZA6j2PhXSUg&t=1331s | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment