FormsSignupForm
Searchastronomic.dev# SignupForm
For an email signup that posts to your newsletter provider with no JavaScript, such as Buttondown or Mailchimp.
Interactive: inline script.
## Usage
```astro
import SignupForm from "@astronomic-dev/ui/components/SignupForm.astro";
```
## Examples
### A plain post
One email field with its visible label, the button under it, and a privacy line in the note slot. It posts to # here: set action to your provider's endpoint, emailName to the field name it wants, and hiddenFields to anything else it asks for. A plain post is the safe default and works with no JavaScript.
```astro
---
import SignupForm from "@astronomic-dev/ui/components/SignupForm.astro";
---
<SignupForm class="max-w-md" action="#">
<p slot="note" class="m-0">One email a month. Unsubscribe at any time.</p>
</SignupForm>
```
### Buttondown
Buttondown's row: action is https://buttondown.com/api/emails/embed-subscribe/<user>, with <user> your Buttondown username (copy it from the embed code under Settings, Embedding; example here is a placeholder), the email field is email, and the hidden fields are embed=1 and, if you like, a tag. Use a plain post: Buttondown asks not to send it with fetch, because it may show its own CAPTCHA page. After the post Buttondown shows its own page.
```astro
---
import SignupForm from "@astronomic-dev/ui/components/SignupForm.astro";
// Buttondown: the embed-subscribe endpoint with your username, embed=1 and an optional tag. A plain post only.
---
<SignupForm
class="max-w-md"
action="https://buttondown.com/api/emails/embed-subscribe/example"
hiddenFields={[
{ name: "embed", value: "1" },
{ name: "tag", value: "site" },
]}
>
<p slot="note" class="m-0">One email a month. Unsubscribe at any time.</p>
</SignupForm>
```
### Mailchimp
Mailchimp's row: copy the form's action from your audience's embedded form code as it is, with its query (u, id and f_id; the values here are made up). The email field is EMAIL, and the honeypot is Mailchimp's own trap, b_<u>_<id>, from the same code. Use a plain post: the form endpoint answers a page, not JSON. After the post Mailchimp shows its own page.
```astro
---
import SignupForm from "@astronomic-dev/ui/components/SignupForm.astro";
// Mailchimp: the action, EMAIL and the b_<u>_<id> trap, copied from the embedded form code. A plain post only.
---
<SignupForm
class="max-w-md"
action="https://example.us1.list-manage.com/subscribe/post?u=abc123&id=def456&f_id=00a1b2"
emailName="EMAIL"
honeypot={{ name: "b_abc123_def456" }}
>
<p slot="note" class="m-0">One email a month. Unsubscribe at any time.</p>
</SignupForm>
```
## Props
### SignupForm
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `action` | `string` | None | Required. The URL the form posts to. Any endpoint that takes a form post works; copy it from your provider's embed code as it is (Mailchimp's keeps its query, u, id and f_id). |
| `method` | `"post" \| "get"` | `"post"` | How the form sends. Only post is enhanced. |
| `enctype` | `"application/x-www-form-urlencoded" \| "multipart/form-data"` | None | How a post is encoded: URL-encoded (the browser's default) or multipart, for files. Not used with get. |
| `hiddenFields` | `HiddenField[]` | `[]` | Extra fields the endpoint wants, sent as <input type="hidden">: { name, value }[], such as Buttondown's embed=1 and a tag. They come first in the body, in order; a name may repeat. Not `hidden`, which is the HTML attribute. |
| `honeypot` | `Honeypot` | None | The spam trap, off by default: { name }. One empty text field real people never see; the endpoint rejects posts that fill it. Use the provider's own name: Mailchimp's b_<u>_<id>, Formspree's _gotcha. Avoid names autofill knows (email, name, url). |
| `submitLabel` | `string` | `"Subscribe"` | The button text. The button is always a submit button. |
| `submitVariant` | `"primary" \| "secondary" \| "ghost"` | `"primary"` | The submit Button's variant, Button's own. Keep primary when the form is the main action; use secondary when another action near it is the main one, such as a sign-in form under a paywall's Subscribe Button. It takes the form's tone. |
| `submitIconTile` | `IconComponent` | None | Off by default. The submit Button's iconTile: a tile at the end of the pill that holds your icon component (an arrow), the inverted pair of the button's colors, its corners nested in the pill's (--ui-radius-pill). The icon is decoration and moves on hover and focus where motion is allowed (submitTileMotion). |
| `submitTileMotion` | `"turn" \| "slide"` | `"turn"` | The submit Button's tileMotion, with submitIconTile: turn turns the icon on hover and focus; slide moves it out of its tile while a copy moves in. Still under reduced motion or the theme's calm setting. |
| `submitRoll` | `boolean` | `false` | The submit Button's roll: on hover and keyboard focus the label rolls up and the same words roll in from below, read once. Off under reduced motion or the theme's calm setting. |
| `enhance` | `"none" \| "fetch"` | `"none"` | none: a plain post, the safe default for any endpoint. fetch: Form's script sends in the page and says the result in the FormStatus. fetch needs a same-origin or CORS-enabled endpoint that answers JSON with a real status code (Formspree does, with Accept: application/json). A cross-origin endpoint without CORS still receives the post, but the page cannot read the answer, so it shows the error text. Success is a 2xx JSON answer, or 204 No Content; a provider that answers an HTML page, even with 200, reads as an error. Buttondown and Mailchimp must use a plain post. Only method="post" is enhanced. |
| `sendingText` | `string` | None | FormStatus's text while sending (enhance="fetch"). Default "Sending…". |
| `successText` | `string` | `"Thanks. Check your inbox to confirm."` | FormStatus's text on a 2xx JSON answer or 204 (enhance="fetch"), such as a line that says to confirm by email. |
| `errorText` | `string` | None | FormStatus's text on any other answer or no network (enhance="fetch"). Default "It did not send. Check your connection and try again." |
| `target` | `string` | None | Passed to <form>, such as _blank to open the provider's own page in a new tab. |
| `tone` | `"page" \| "band"` | `"page"` | The surface: page, or band for a surface-band area, where the Button, the status and every focus ring take the band's colors. Give each Field the same tone. |
| `emailName` | `string` | `"email"` | The email field's name, as your endpoint wants it: email for Buttondown and Formspree, EMAIL for Mailchimp. |
| `emailLabel` | `string` | `"Email"` | The email field's label. |
| `labelHidden` | `boolean` | `false` | Keep the field labels (email, and name with nameField) for screen readers only, when the heading beside the form already says what the fields are for (NewsletterInline does). The fields then show emailPlaceholder and namePlaceholder as hints. |
| `emailPlaceholder` | `string` | `labelHidden ? "Email address" : undefined` | A hint inside the empty email field: "Email address" when the label is hidden, else none. It is never the label: the label is always there, shown or for screen readers. |
| `nameField` | `boolean` | `false` | Ask for a name too, before the email (optional to fill, autocomplete name). |
| `nameName` | `string` | `"name"` | The name field's name (with nameField), such as FNAME for Mailchimp. |
| `nameLabel` | `string` | `"Name"` | The name field's label (with nameField), shown unless labelHidden. |
| `namePlaceholder` | `string` | `labelHidden ? "Your name" : undefined` | A hint inside the empty name field (with nameField): "Your name" when the label is hidden, else none. It is never the label. |
| `layout` | `"stacked" \| "inline"` | `"stacked"` | stacked: the button under the field. inline: the field and button in one row, the button dropping under the field in a narrow box; the status is a full line under the row. |
| `fieldErrors` | `{ email?: string }` | `{}` | The text shown under the email field when it is empty or wrong, with enhance="fetch", in your page's language. Default "Enter an email address, like name@example.com.". It goes on the control as data-error; with no script the browser shows its own message. |
| `class` | `string` | None | More classes for the <form>, merged with cn(), so yours win on conflicts, such as a reading width (max-w-md). |
| Slot | Description |
| --- | --- |
| `extra` | After the fields, before the button: more fields or a widget, such as a consent box. Keep submit buttons out of it. |
| `note` | Under the form, small and muted: the privacy line. |
Any other attribute goes on the <form>, such as id or aria-label.
## Accessibility
| Key | Action |
| --- | --- |
| Enter | In the email or name field, submits the form |
| Tab | Moves through the fields, the button, then any links in the note, then out of the form; the status is skipped |
- Each field has a visible label, or, with labelHidden, a label kept for screen readers only, when the heading beside the form already says what it is for. A placeholder is only a hint, never the label.
- The email field is type=email with autocomplete email and no spellcheck, and is required and marked so; the optional name field has autocomplete name.
- The note slot holds the privacy line (how often you write, how to unsubscribe), under the form, small and muted.
- With no script, or before it loads, the form posts to its action and the browser checks the email itself. Buttondown, Mailchimp and Formspree each show their own page after the post, so a signup works with no JavaScript.
- With enhance="fetch", a bad email gets its error text under the field, aria-invalid and the error id in aria-describedby, and focus moves to it. The FormStatus under the button says sending, then success or the error. Use it only with an endpoint that answers JSON (Formspree); Buttondown and Mailchimp must use a plain post.
- The button is never disabled: while sending it has aria-busy, and a second click or Enter is ignored.
SignupForm
FreeFor an email signup that posts to your newsletter provider with no JavaScript, such as Buttondown or Mailchimp.
- File
- SignupForm.astro
- Group
- Forms
- Kind
- Interactive: inline script
- Examples
- 3
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
A plain post
One email field with its visible label, the button under it, and a privacy line in the note slot. It posts to # here: set action to your provider's endpoint, emailName to the field name it wants, and hiddenFields to anything else it asks for. A plain post is the safe default and works with no JavaScript.
This preview did not load.
examples/signupform/main.astro
---
import SignupForm from "@astronomic-dev/ui/components/SignupForm.astro";
---
<SignupForm class="max-w-md" action="#">
<p slot="note" class="m-0">One email a month. Unsubscribe at any time.</p>
</SignupForm>Buttondown
Buttondown's row: action is https://buttondown.com/api/emails/embed-subscribe/<user>, with <user> your Buttondown username (copy it from the embed code under Settings, Embedding; example here is a placeholder), the email field is email, and the hidden fields are embed=1 and, if you like, a tag. Use a plain post: Buttondown asks not to send it with fetch, because it may show its own CAPTCHA page. After the post Buttondown shows its own page.
Mailchimp
Mailchimp's row: copy the form's action from your audience's embedded form code as it is, with its query (u, id and f_id; the values here are made up). The email field is EMAIL, and the honeypot is Mailchimp's own trap, b_<u>_<id>, from the same code. Use a plain post: the form endpoint answers a page, not JSON. After the post Mailchimp shows its own page.
This preview did not load.
examples/signupform/mailchimp.astro
---
import SignupForm from "@astronomic-dev/ui/components/SignupForm.astro";
// Mailchimp: the action, EMAIL and the b_<u>_<id> trap, copied from the embedded form code. A plain post only.
---
<SignupForm
class="max-w-md"
action="https://example.us1.list-manage.com/subscribe/post?u=abc123&id=def456&f_id=00a1b2"
emailName="EMAIL"
honeypot={{ name: "b_abc123_def456" }}
>
<p slot="note" class="m-0">One email a month. Unsubscribe at any time.</p>
</SignupForm>