0Pricing
Sveltejs Academy · Lesson

+page.server.js with actions

Define named and default action handlers in +page.server.js to process form data.

Form Actions Intro

SvelteKit lets you handle form submissions on the server via action handlers in +page.server.js.

Default Action

Export an actions object with a default handler for unnamed forms.

export const actions = {
  default: async ({ request }) => {
    const data = await request.formData();
    // ...
  }
};

All lessons in this course

  1. +page.server.js with actions
  2. The use:enhance Directive
  3. Progressive Enhancement for Forms
  4. Handling Validation Errors in Actions
← Back to Sveltejs Academy