| 1 | --- |
| 2 | // Server-handled form POST: GET renders the form; POST (same route) reads |
| 3 | // the multipart/urlencoded body server-side and re-renders with the echoed |
| 4 | // message. Direct fetch() POSTs (no Origin header) work because the user |
| 5 | // config sets `security.checkOrigin: false`. |
| 6 | let submitted: string | null = null; |
| 7 | if (Astro.request.method === "POST") { |
| 8 | const data = await Astro.request.formData(); |
| 9 | submitted = data.get("message")?.toString() ?? null; |
| 10 | } |
| 11 | --- |
| 12 | |
| 13 | <html lang="en"> |
| 14 | <head> |
| 15 | <meta charset="utf-8" /> |
| 16 | <title>Feedback</title> |
| 17 | </head> |
| 18 | <body> |
| 19 | <h1>Feedback</h1> |
| 20 | {submitted !== null && <p id="feedback-result">received: {submitted}</p>} |
| 21 | <form method="POST" action="/feedback"> |
| 22 | <input id="message" name="message" type="text" /> |
| 23 | <button id="submit" type="submit">Send</button> |
| 24 | </form> |
| 25 | </body> |
| 26 | </html> |