Svelte dynamic form

Build a dynamic, schema-driven form in Svelte with no backend. Render the inputs from a fields array with {#each}, so you add or reorder fields by editing data. It posts once to Formpaste. Copy the component and add your access key.

How to build it

  1. Create a form in your Formpaste dashboard and copy its access key.
  2. Copy the schema-driven component below and edit the fields array to your form.
  3. Replace YOUR_ACCESS_KEY_HERE with your access key, then deploy.

Prompt for your AI coding agent

Add a Formpaste dynamic form to my Svelte app. Use a single-file component that renders inputs from a fields array with {#each}, binds each with bind:value into a data object, and POSTs once as application/x-www-form-urlencoded (URLSearchParams) to https://api.formpaste.com/submit with a hidden access_key. The fields should come from a schema, not hardcoded markup.

Or connect the Formpaste MCP server to Claude Code, Codex, Cursor, Claude Desktop, VS Code, or any mcp-remote client. See the setup guide.

Svelte gotchas

A Svelte contact form is a single-file component with bind:value on the fields and an on:submit|preventDefault handler that posts to Formpaste. There is no backend and no API of your own. Put the fetch in the component and you are done.

It is a single-file component

The form lives in a .svelte component with a <script> block. Bind the fields with bind:value or read a FormData off the form element on submit, then post to the Formpaste endpoint. No store or library is required for a simple form.

No API of your own

You do not proxy through your own server. The component posts straight to the Formpaste endpoint, which removes a mailer and a submissions store you would otherwise build.

Handle the response with a reactive status

The endpoint returns JSON (success, message, id). Await the fetch and set a reactive status variable to show your own success or error state, or set a redirect URL in the dashboard and skip the client handling.

Svelte 4 or Svelte 5, both work

The examples use a <script> block with a plain status variable, which works in every Svelte version. On Svelte 5 you can use runes like $state instead, but the same fetch and the same POST are all Formpaste needs.

What to get right

The fields come from a schema, not the markup

A dynamic form renders its inputs from an array of field definitions, so you add or reorder fields by editing data, not JSX or template markup. The same component handles any field-set.

One submit for any shape

However many fields the schema has, the form posts once to Formpaste as a single submission. Keep the hidden access_key input in the payload and the field names meaningful so your inbox is readable.

Keep field names stable

The field name is what shows up in your inbox and exports, so name each schema entry clearly (name, email, message) even as you change labels or order. Formpaste stores whatever names you send.

How it works

Three simple steps for form submissions to land in your email inbox.
Create your form, set your form's action URL to Formpaste's endpoint, and add your access key.

1

Create your form

Sign up, verify your email, and create an access key in your dashboard.

2

Copy the code

Paste the snippet above into your project. Pick CSS or Tailwind to match your site.

<script lang="ts">
  const ENDPOINT = "https://api.formpaste.com/submit";

  const fields = [
    { name: "name", type: "text", label: "Name" },
    { name: "email", type: "email", label: "Email" },
    { name: "message", type: "textarea", label: "Message" },
  ];

  let data: Record<string, string> = Object.fromEntries(
    fields.map((f) => [f.name, ""])
  );

  async function submit() {
    const body = new URLSearchParams({ access_key: "YOUR_ACCESS_KEY_HERE", ...data });
    await fetch(ENDPOINT, { method: "POST", body });
  }
</script>

<form on:submit|preventDefault={submit}>
  {#each fields as f}
    <label>
      {f.label}
      {#if f.type === "textarea"}
        <textarea bind:value={data[f.name]} />
      {:else}
        <input type={f.type} bind:value={data[f.name]} />
      {/if}
    </label>
  {/each}
  <button type="submit">Send</button>
</form>
3

Add your access key

Replace the placeholder with your access key to start receiving submissions.

<input type="hidden" name="access_key" value="YOUR_ACCESS_KEY_HERE">

Svelte dynamic form FAQ

Paste a form. Get submissions.

Instantly without setting up any backend, servers or databases. 250 submissions/mo free - no credit card.

Other Svelte forms