{}
Submit JSON with Svelte
Use the Submit JSON JS Client to wire up a contact us form submission notification using Svelte.
Set up your Svelte project
- To get started, make sure you have a working Svelte project. If you do not, follow these instructions.
- Then install
submitjsonwith your favorite package manager.
pnpm add submitjson # OR npm i OR yarn add
shell
Integrate Submit JSON with Svelte
Next initialize the client and handle the contact us form submission in your Svelte component:
<script>
import SubmitJSON from 'submitjson'
const sj = new SubmitJSON({ apiKey: 'sjk_xxx', endpoint: 'xxx' })
let name = ''
let email = ''
let message = ''
async function submit() {
await sj.submit({ name, email, message })
}
</script>
<form on:submit|preventDefault={submit}>
<input type="text" bind:value={name}>
<input type="email" bind:value={email}>
<textarea bind:value={message}>
<button type="submit">
Submit
</button>
</form>
html
🚛✨💚 Nice job, you successfully integrated Submit JSON with Svelte.
Updated on 01/11/2023
