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
|
async function submitUserProfile(formData: FormData) {
"use server";
const name = formData.get("name");
const age = formData.get("age");
const favoriteColor = formData.get("favoriteColor");
const hobby = formData.get("hobby");
const isSubscribed = formData.get("newsletter") === "on";
console.log({
name,
age,
favoriteColor,
hobby,
isSubscribed,
});
}
export const ServerForm = () => {
return (
<form action={submitUserProfile} className="space-y-4">
<div style={{ display: "flex", gap: 4, marginBottom: 4 }}>
<label htmlFor="name">Full Name</label>
<input type="text" name="name" id="name" required />
</div>
<div style={{ display: "flex", gap: 4, marginBottom: 4 }}>
<label htmlFor="age">Age</label>
<input type="number" name="age" id="age" min="13" max="120" />
</div>
<div style={{ display: "flex", gap: 4, marginBottom: 4 }}>
<label htmlFor="favoriteColor">Favorite Color</label>
<select name="favoriteColor" id="favoriteColor">
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
<option value="purple">Purple</option>
<option value="yellow">Yellow</option>
</select>
</div>
<div style={{ display: "flex", gap: 4, marginBottom: 4 }}>
<label htmlFor="hobby">Favorite Hobby</label>
<input
type="text"
name="hobby"
id="hobby"
placeholder="e.g. Reading, Gaming, Cooking"
/>
</div>
<div style={{ display: "flex", gap: 4, marginBottom: 4 }}>
<label>
<input type="checkbox" name="newsletter" />
Subscribe to newsletter
</label>
</div>
<button
type="submit"
className="hover:bg-slate-50 w-fit rounded-lg bg-white p-2"
>
Save Profile
</button>
</form>
);
};
|