Formpost

Framework guides

Svelte

A component that posts the form and keeps the page in place.

Bind the submit handler, post the form’s own FormData, and let the response drive whatever you render. Same shape in SvelteKit.

ContactForm.svelte
<script>
  let sent = false;
  let error = "";

  async function submit(event) {
    const body = new FormData(event.currentTarget);
    body.append("access_key", "YOUR_ACCESS_KEY_HERE");

    const res = await fetch("https://api.formpost.ai/submit", {
      method: "POST",
      headers: { Accept: "application/json" },
      body,
    });

    const result = await res.json();
    if (result.success) sent = true;
    else error = result.message;
  }
</script>

<form on:submit|preventDefault={submit}>
  <input name="name" required />
  <input type="email" name="email" required />
  <textarea name="message" required></textarea>
  <button type="submit">Send</button>
  {#if sent}<p>Thanks — we will be in touch.</p>{/if}
  {#if error}<p>{error}</p>{/if}
</form>