FormsMessageForm

Open in Create
Search
astronomic.dev

MessageForm

Free

For a message form that posts to your endpoint with no JavaScript: name, email and message, plus company, phone or a topic if you ask.

File
MessageForm.astro
Group
Forms
Kind
Interactive: inline script
Examples
4
import MessageForm from "@astronomic-dev/ui/components/MessageForm.astro";

Examples

Drag the orange handle to set the width. Frames get real breakpoints.

  • Static
  • Interactive
  • Framed

A plain post

Name, email and message, each with a visible label, then the button, and a privacy line in the note slot. It posts to # here: set action to your endpoint. A plain post is the safe default and works with any endpoint that takes a form post, with no JavaScript.

main.astro

Company, phone and topics

company and phone add two optional fields after the email; topics adds a native select before the message, which opens on "Choose a topic" (topicPlaceholder) so no topic is sent until the reader picks one.

topics.astro

Sent in the page

enhance="fetch": the form checks its fields when sent, shows each error under its field and moves focus to the first, then sends in the page and says the result under the button. Here it posts to the directory's test endpoint, which exists only in development and in tests; on this site, with no endpoint behind it, the preview answers in the page, so it says it was sent and nothing is kept. A real endpoint must answer JSON.

enhanced.astro

Formspree, sent in the page

Formspree's setup: action is your form's endpoint, https://formspree.io/f/<id> (copy the id from your Formspree form; xyzabcde here is made up), and the honeypot is Formspree's own spam trap, _gotcha. Formspree answers JSON to the script (Accept: application/json, with CORS), so enhance="fetch" sends in the page and the status under the button says it was sent. Without the script it is a plain post, and Formspree shows its own thank-you page. On this site the made-up id does not exist, so sending shows the error text.

formspree.astro
Minimal · Light

Waitlist

Be first in line

Join the waitlist and we'll email you the moment it's out.

You'll also get our newsletter: new themes, plugins and guides. Unsubscribe any time.