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.