Bonus lesson

A working contact form

Proof that a "static" site can still do real backend work — no separate server required.

How this actually works. The form below sends your message to /api/contact, a small Cloudflare Pages Function (serverless code that ships alongside the site). That function validates the input and saves it into a Cloudflare D1 database. All of it lives in this same repository and deploys on the same git push.


Why a static site needs a "Function" for this

Remember Lesson 1: a static site is just files handed to the browser. There's no program running on the server to receive a form and do something with it. A Pages Function fills exactly that gap — it's a snippet of code Cloudflare runs on demand when a request hits a certain URL. You get the simplicity of static hosting and a little backend when you need one.

the whole flow
Browser (this form)
   │  sends name / email / message as JSON
   ▼
/api/contact          ← functions/api/contact.js (runs on Cloudflare)
   │  validates + blocks spam
   ▼
D1 database           ← stores every submission (SQLite in the cloud)
Where do the messages go? Straight into the project's D1 database. You can read them from the Cloudflare dashboard (Workers & Pages → D1), or just ask Claude Code to fetch the latest submissions for you.