Loading SvelteCosmos...
“SvelteKit Form Actions let you handle POST mutations in +page.server.ts. Combined with use:enhance, forms work with 100% functionality without JavaScript enabled, and upgrade to seamless AJAX submissions with JS.”
Handle server mutations seamlessly with zero client JavaScript and progressive enhancement via use:enhance.
// +page.server.ts
export const actions = {
default: async ({ request }) => {
const data = await request.formData();
const email = data.get('email');
if (!email) return fail(400, { missing: true });
await db.subscribe(email);
return { success: true };
}
};
// +page.svelte
<script>
import { enhance } from '$app/forms';
let { form } = $props();
</script>
<form method="POST" use:enhance>
<input name="email" type="email" required />
<button>Subscribe</button>
{#if form?.success}
<p>Subscribed successfully!</p>
{/if}
</form>Modify the state variable below to watch the signal update the output without VDOM diffing:
Zero client JS payload required for form submission; server automatically handles redirect and cookie sessions.