|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: Urgent Contact |
| 4 | +--- |
| 5 | + |
| 6 | +If you have an access token then you can send me an urgent message using this form: |
| 7 | + |
| 8 | +<form id="contact-form" method="post" action="/api/contact-urgent"> |
| 9 | + <fieldset style="display:none"> |
| 10 | + <label for="name">Leave blank if you're human:</label> |
| 11 | + <input type="text" name="name" id="name" placeholder="Leave blank if you're human"> |
| 12 | + </fieldset> |
| 13 | + <fieldset style="margin-bottom:1em"> |
| 14 | + <label for="email" style="display:inline-block; margin-bottom:0.5em">Email address:</label> |
| 15 | + <input type="email" name="email" id="email" placeholder="Email address" style="box-sizing:border-box; width:100%; max-width:20em" required> |
| 16 | + </fieldset> |
| 17 | + <fieldset style="margin-bottom:0.5em"> |
| 18 | + <label for="message">Message:</label> |
| 19 | + </fieldset> |
| 20 | + <fieldset style="margin-bottom:1em"> |
| 21 | + <textarea name="message" id="message" placeholder="Message" style="box-sizing:border-box; width:100%; max-width:60em; height:15em" required></textarea> |
| 22 | + </fieldset> |
| 23 | + <fieldset style="margin-bottom:1em"> |
| 24 | + <label for="token" style="display:inline-block; margin-bottom:0.5em">Token:</label> |
| 25 | + <input type="text" name="token" id="token" placeholder="token" style="box-sizing:border-box; width:100%; max-width:20em" required> |
| 26 | + </fieldset> |
| 27 | + <button type="submit" style="margin-bottom:1em">Send</button> |
| 28 | +</form> |
| 29 | + |
| 30 | +<script> |
| 31 | + document.getElementById("contact-form").addEventListener("submit", event => { |
| 32 | + event.preventDefault() |
| 33 | + const formData = new FormData(event.target); |
| 34 | + const token = formData.get("token"); |
| 35 | + fetch("/api/token-verify", { |
| 36 | + method: "POST", |
| 37 | + headers: { |
| 38 | + "accept": "application/json", |
| 39 | + "content-type": "application/json" |
| 40 | + }, |
| 41 | + body: JSON.stringify({ token }) |
| 42 | + }) |
| 43 | + .then(res => res.json()) |
| 44 | + .then(res => { |
| 45 | + const element = document.getElementById("token-verify-output"); |
| 46 | + if (!res.ok) { |
| 47 | + alert(`Token ${token} does not appear to be valid.`) |
| 48 | + } else { |
| 49 | + fetch("/api/contact-urgent", { |
| 50 | + method: "POST", |
| 51 | + headers: { |
| 52 | + "accept": "application/json", |
| 53 | + "content-type": "application/json", |
| 54 | + }, |
| 55 | + body: JSON.stringify(Object.fromEntries(formData.entries())) |
| 56 | + }) |
| 57 | + .then(res => res.json()) |
| 58 | + .then( |
| 59 | + alert("Your message has been sent successfully.") |
| 60 | + event.target.reset() |
| 61 | + ) |
| 62 | + } |
| 63 | + }); |
| 64 | + }); |
| 65 | +</script> |
0 commit comments