Svelte and SvelteKit 5 · SvelteKit

Handle a form on the server

Form actions receive the submitted form data. The form works without JavaScript and can be enhanced with use:enhance.

// +page.server.ts
import { fail } from "@sveltejs/kit";

export const actions = {
  default: async ({ request }) => {
    const data = await request.formData();
    const email = data.get("email");
    if (!email) return fail(400, { error: "Email is required" });
    return { success: true };
  },
};

Official Svelte and SvelteKit 5 documentation

More sveltekit commands

All sveltekit commands · Svelte and SvelteKit 5 cheatsheet

Was this page helpful?