Hosting and deploy platforms
Add a contact form to Cloudflare Pages
Cloudflare Pages Functions are excellent, and completely unnecessary for a contact form. Writing one means owning a Worker, an email API integration and your own spam filtering, all to move some form fields into an inbox. Point the form at an endpoint instead and there is no Function, no binding and no wrangler config in the loop.
Setup
Copy your endpoint
Create a form in the dashboard.
Point the form at it
A native POST or a client-side fetch. Neither needs a Function.
Optionally use an env var
Set a build-time variable in the Pages dashboard if you want different forms per environment.
Cloudflare Pages examples
Swap in your own endpoint and these run as-is.
Static, no Function involved.
<form action="https://send.webforms.to/wft_your_key" method="POST"> <input type="text" name="name" required /> <input type="email" name="email" required /> <textarea name="message" required></textarea> <input type="hidden" name="_next" value="https://example.com/thanks" /> <button type="submit">Send</button> </form>
Only if you specifically want the submission to pass through a Pages Function first.
export const onRequestPost: PagesFunction = async ({ request }) => {
const formData = await request.formData();
const res = await fetch("https://send.webforms.to/wft_your_key", {
method: "POST",
headers: { accept: "application/json" },
body: formData,
});
return new Response(await res.text(), {
status: res.status,
headers: { "content-type": "application/json" },
});
};Cloudflare Pages form FAQ
No. The browser posts straight to the endpoint. A Function is only useful if you want to add your own logic in front of it.
Yes. The submission goes to our endpoint rather than back through your zone, so your WAF rules are not involved in the POST.
Related guides
Ready to wire up your Cloudflare Pages form?
Free for 300 submissions a month. Endpoint in under a minute, no card required.
Start free