Station 12 · Forms & server actions
Most of the web is two computers passing notes. The patron's browser packs an envelope. Our server reads it, does something, writes back. Then the browser unfolds the reply and rerenders the page. That round trip is the most important shape in programming, and on this stack it is shorter than you think.
Below is a miniature of our real donate form. Press Send it and watch every leg of the trip — collect, send, process, respond, rerender — in the order they happen. Read the script and you have read the actual file under app/donate.
1// actions.ts — runs on the SERVER2"use server";34export async function donate(formData) {5const amount = formData.get("amount");6// talk to Stripe here, save to the database, etc.7return { ok: true, amount };8}910// page.tsx — rendered on the server, shipped to BROWSER11<form action={donate}>12<input name="amount" type="number" />13<button type="submit">Send it</button>14</form>
Hover any line. Then press Send it and watch every leg of the round trip light up in order.
Browser
1 · Collect
browser packs the form into a request
2 · Send
request travels across the wires
3 · Server runs
serverdonate(formData) executes on our server
4 · Respond
server hands a result back to the browser
5 · React updates
the page rerenders with the result
A server action is a function the browser is allowed to call as if it were local — except it actually runs on our machine, with access to Stripe and the database. The "use server" line at the top of the file is the whole magic. Everything else is plain JavaScript.
Curriculum complete · all twelve stations open