SvelteKit Quickstart
Add a working contact form to a SvelteKit app. You write the form, and Formerie checks it, stores it, and emails you.
Install
Install @formerie/svelte
Shell
npm install @formerie/svelte Shell
pnpm add @formerie/svelte Shell
yarn add @formerie/svelte Shell
bun add @formerie/svelteAdd The Form
Save this as src/routes/contact/+page.svelte, or add it to the page you already have.
<script>
import { createFormerieSubmit } from "@formerie/svelte";
const contact = createFormerieSubmit({ workspace: "acme", form: "contact" });
const { result, isSubmitting } = contact;
function onsubmit(event) {
event.preventDefault();
contact.submit({ fields: Object.fromEntries(new FormData(event.currentTarget)) });
}
</script>
<form method="post" {onsubmit}>
<input name="name" placeholder="Name" required />
<input name="email" type="email" placeholder="Email" required />
<textarea name="message" placeholder="Message" required></textarea>
<button disabled={$isSubmitting}>Send</button>
{#if $result?.ok === true}<p>Thanks!</p>{/if}
{#if $result?.ok === false}<p>{$result.error.message}</p>{/if}
</form>Each input’s name is the field it fills in Formerie.
Set Up The Form In The App
- Open app.formerie.com and create a form named Contact. It comes with the name, email, and message fields this code sends.
- On the Delivery tab, add your email address, then choose Save delivery. Confirm the email Formerie sends you.
- On the Publish tab, choose API-only and add the address your dev server prints, such as
http://localhost:5173, under Your website addresses.localhostand127.0.0.1count as different addresses. Add your live site’s address the same way when you deploy. - Choose Publish form.
- In the code above, replace
acmewith the workspace handle shown on the Publish tab.
Check It Arrived
Run your app, fill in the form, and send it. “Thanks!” appears on the page. In the app, your response shows under Submissions, and its email under Deliveries.
Seeing a CORS error, or NETWORK_ERROR? Your site’s address isn’t on the Publish tab yet, or you haven’t published since adding it.
See Troubleshooting.
Read Next
- Recipes: quote requests, surveys, and routing by topic
- Show field errors and more
- SvelteKit form actions, if the form has to work without JavaScript
- JavaScript SDK and API: the full reference