Basic Actions in Svelte

From the SvelteKit cheat sheet ยท Form Actions ยท verified Nov 2026

Basic Actions

Server-side form handling

javascript
// +page.server.js
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, { missing: true });
    }

    // Process form
    return { success: true };
  }
};

// +page.svelte
<script>
  let { form } = $props();
</script>

<form method="POST">
  {#if form?.missing}<p>Email is required</p>{/if}
  <input name="email" type="email" />
  <button>Submit</button>
</form>
๐Ÿ“ Progressive enhancement - works without JavaScript
๐Ÿ”’ Server-side validation with fail(status, data)
๐Ÿช Direct cookie access for authentication
๐Ÿ“Œ A page has one default action or named actions, not both

Continue with SvelteKit

Save the full cheat sheet or work through every related task.

More Svelte tasks

Back to the full SvelteKit cheat sheet