Actions are exported from the +page.server.js
file. Actions have access to the form data passed through the request.
Actions can be called through forms in Svelte components. When calling the the default action of a page, an action
attribute is not required.
export const actions = {
default: async ({ request }) => {
const formData = await request.formData();
const data = { email: formData.get('email') };
await fetch('https://mailcoach.app/api/…', {
method: 'POST',
body: JSON.stringify(data),
});
},
};
<form method="POST">
<label>Email</label>
<input type="email">
</form>