Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// This val will respond with a styled HTML form for users to input their name
export default async function (req: Request): Promise<Response> {
if (req.method === "POST") {
const formData = new URLSearchParams(await req.text());
const name = formData.get("name") ?? "Stranger"; // Default to "Stranger" if no name provided
return new Response(`<h1 style="color: #333; text-align: center;">Hello, ${name}!</h1>`, { headers: { "Content-Type": "text/html" } });
}
return new Response(`
<html>
<head>
<title>Greetings Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f9f9f9;
margin: 0;
padding: 10px;
}
h1 {
color: #27ae60;
text-align: center;
}
form {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20px;
}
label {
font-size: 1.2em;
margin-bottom: 5px;
color: #333;
}
input[type="text"] {
padding: 5px;
width: 200px;
border: 1px solid #333;
border-radius: 5px;
}
button {
padding: 8px 15px;
margin-top: 10px;
background-color: #27ae60;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #2ecc71;
}
</style>
</head>
<body>
<h1>Welcome!</h1>
<form method="post">
<label for="name">Enter your name:</label>
<input type="text" id="name" name="name">
<button type="submit">Submit</button>
</form>
</body>
</html>
`, { headers: { "Content-Type": "text/html" } });
}
janpaul123-valle_tmp_82429476471184249764330565705816.web.val.run
July 15, 2024