Public
HTTP
Forked from stevekrouse/form
stevekrouse-docfeedbackform.web.val.run
October 23, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { waterCSS } from "https://esm.town/v/stevekrouse/waterCSS";
import { html } from "https://esm.town/v/stevekrouse/html";
import { set } from "https://esm.town/v/std/set?v=11";
import { docsFeedback } from "https://esm.town/v/stevekrouse/docsFeedback";
export let docFeedbackForm = async (req: Request) => {
if (req.method === "POST") {
let formData = await req.formData();
docsFeedback.push({
time: Date.now(),
feedback: formData.get("feedback"),
url: formData.get("url"),
email: formData.get("email"),
});
await set(
"docsFeedback",
docsFeedback,
);
return html("Thanks for your feedback!", {
headers: {
"Set-Cookie": `email=${formData.get("email")}`,
},
});
}
const { getCookies } = await import("https://deno.land/std/http/cookie.ts");
let ref = new URL(req.url).searchParams.get("ref") ?? "";
let email = getCookies(req.headers).email ?? "";
return html(`${waterCSS}
<div style="margin-left: auto;margin-right: auto;width: 500px;padding: 30px;">
<h1>Val Town Docs Feedback</h1>
<form action="https://stevekrouse-docFeedbackForm.web.val.run" method="post">
<textarea name="feedback" placeholder="Feedback..." rows="4" cols="50"></textarea>
<br/><input name="url" value="${ref}" placeholder="URL" size="50" />
<br/><input name="email" value="${email}" placeholder="Email" size="30" />
<br/> <button>Submit</button>
</form>
<a href="https://www.val.town/v/stevekrouse.docFeedbackForm"><b><i>vt</i></b> source code</a>
</div>`);
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023