Alpine.js comment form

Add a comment form to any page with Alpine.js and no backend. The @submit.prevent handler posts with fetch so the reader stays where they are, and comments land in your inbox for review. Copy the markup and add your access key.

How to build it

  1. Create a form in your Formpaste dashboard and copy its access key.
  2. Add the Alpine script tag and the markup above to your post template.
  3. Replace YOUR_ACCESS_KEY_HERE with your access key, then publish.

Alpine.js gotchas

Alpine adds behaviour to markup you already have. Drop in the script tag, put x-data on the form, and a submit handler posts to Formpaste. There is no build step, no components, and no backend of your own.

It is a script tag, not a build step

Alpine loads from a CDN with a deferred script tag. There is nothing to compile and no bundler to configure, so the same form works in a static site, a CMS template, or a hand-written page.

Keep the real action attribute

Leave action pointing at the Formpaste endpoint. If Alpine fails to load, the browser still posts the form the ordinary way, so the directives are an upgrade rather than a requirement.

x-data holds the state

Put the small pieces of state on the form itself with x-data, then use @submit.prevent to post and x-show to swap in a thank-you message. No store and no extra library is needed for a form.

Keep the hidden access_key

Leave the generated hidden access_key input in place so Formpaste knows which form the submission belongs to. Alpine does not touch it.

What to get right

Static sites have no comment backend, so a form fills the gap

A statically generated page cannot store comments on its own. Posting to Formpaste gives you a place for them to land without adding a database or a CMS.

Moderate before you publish

Comments are a spam magnet. Formpaste filters obvious spam and quarantines borderline submissions in a folder you review, so you approve what actually appears on the page.

Keep the email private

Collect the commenter's email for moderation and reply, but label it as not published so people know it will not appear on the site.

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 src="https://cdn.jsdelivr.net/npm/alpinejs@3/dist/cdn.min.js" defer></script>
<style>[x-cloak] { display: none !important; }</style>

<div x-data="{ sending: false, sent: false }">
  <form
    action="https://api.formpaste.com/submit"
    method="POST"
    x-show="!sent"
    @submit.prevent="sending = true; await fetch($el.action, { method: 'POST', body: new URLSearchParams(new FormData($el)) }); sending = false; sent = true" class="mx-auto flex w-full max-w-md flex-col gap-4 rounded-xl border border-gray-200 bg-white p-6 shadow-sm dark:border-gray-800 dark:bg-gray-950"
  >
  <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY_HERE">
  <label class="flex flex-col gap-1.5 text-sm font-medium text-gray-900 dark:text-gray-100">Name
    <input type="text" name="name" required class="rounded-md border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 shadow-sm outline-none focus-visible:ring-2 focus-visible:ring-gray-900 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-100 dark:focus-visible:ring-gray-100" />
  </label>
  <label class="flex flex-col gap-1.5 text-sm font-medium text-gray-900 dark:text-gray-100">Email (not published)
    <input type="email" name="email" placeholder="you@example.com" required class="rounded-md border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 shadow-sm outline-none focus-visible:ring-2 focus-visible:ring-gray-900 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-100 dark:focus-visible:ring-gray-100" />
  </label>
  <label class="flex flex-col gap-1.5 text-sm font-medium text-gray-900 dark:text-gray-100">Comment
    <textarea name="comment" required class="min-h-28 rounded-md border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 shadow-sm outline-none focus-visible:ring-2 focus-visible:ring-gray-900 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-100 dark:focus-visible:ring-gray-100"></textarea>
  </label>
  <button type="submit" class="w-full rounded-md bg-gray-900 px-4 py-2 text-sm font-medium text-white shadow-sm transition-colors hover:bg-gray-800 disabled:opacity-60 dark:bg-white dark:text-gray-900 dark:hover:bg-gray-200" :disabled="sending">Post comment</button>
  </form>
  <p x-show="sent" x-cloak>Thanks - your message was sent.</p>
</div>
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">

Alpine.js comment form FAQ

Paste a form. Get submissions.

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

Other Alpine.js forms