Composite
ContactForm
A contact form that posts to a form service or opens the visitor’s mail client.
Basic
The default fields post to an endpoint such as Formspree or Basin. Without JavaScript the form posts natively; with it, success and error show inline and take focus. The hidden _gotcha field follows Formspree’s spam-trap convention; set honeypot to the name your provider drops, or false.
Get in touch
---
import ContactForm from '@alfadormx/blocks/composite/ContactForm.astro';
---
<ContactForm
headline={{ title: 'Get in touch' }}
action={{ type: 'endpoint', url: 'https://formspree.io/f/demo-basic' }}
/>Custom fields
fields takes any form primitive, tagged by control. A provided list replaces the defaults.
---
import ContactForm from '@alfadormx/blocks/composite/ContactForm.astro';
import type { ContactFormField } from '@alfadormx/blocks/types/contactform';
const fields: ContactFormField[] = [
{ control: 'input', name: 'name', label: 'Name', required: true, autocomplete: 'name' },
{
control: 'input',
name: 'email',
label: 'Email',
type: 'email',
required: true,
autocomplete: 'email',
},
{
control: 'select',
name: 'topic',
label: 'Topic',
placeholder: 'Choose a topic',
required: true,
options: [
{ value: 'sales', label: 'Sales' },
{ value: 'support', label: 'Support' },
{ value: 'press', label: 'Press' },
],
},
{
control: 'checkboxGroup',
name: 'interests',
label: 'Interests',
options: [
{ value: 'updates', label: 'Product updates' },
{ value: 'events', label: 'Events' },
{ value: 'hiring', label: 'Hiring' },
],
},
{ control: 'textarea', name: 'message', label: 'Message', required: true, rows: 5 },
{ control: 'checkbox', name: 'consent', label: 'I agree to be contacted', required: true },
];
---
<ContactForm
action={{ type: 'endpoint', url: 'https://formspree.io/f/demo-custom-fields' }}
fields={fields}
/>Shared field config
defaultFieldConfig sets size, intent, shape and label visibility on every field.
---
import ContactForm from '@alfadormx/blocks/composite/ContactForm.astro';
---
<ContactForm
action={{ type: 'endpoint', url: 'https://formspree.io/f/demo-shared-config' }}
defaultFieldConfig={{ size: 'lg', shape: 'square' }}
/>Mailto
No service is needed: the visitor’s mail app opens with the message filled in. Without JavaScript the browser falls back to a native text/plain mailto post.
---
import ContactForm from '@alfadormx/blocks/composite/ContactForm.astro';
---
<ContactForm action={{ type: 'mailto', address: 'hello@example.com' }} />Aside
Content in the aside slot sits beside the form and stacks below it on mobile.
Keizersgracht 1
1015 CC Amsterdam
- Mon–Fri: 9:00–17:00
- Sat–Sun: closed
---
import ContactForm from '@alfadormx/blocks/composite/ContactForm.astro';
import MapBlock from '@alfadormx/blocks/primitives/Map.astro';
---
<ContactForm action={{ type: 'endpoint', url: 'https://formspree.io/f/demo-aside' }}>
<div slot="aside" class="flex flex-col gap-4">
<address class="not-italic">
Example Studio
<br />
Keizersgracht 1<br />
1015 CC Amsterdam
</address>
<ul>
<li>Mon–Fri: 9:00–17:00</li>
<li>Sat–Sun: closed</li>
</ul>
<MapBlock lat={52.37} lon={4.89} height="240px" title="Office location" />
</div>
</ContactForm>Aside left
asidePosition="left" puts the aside before the form.
---
import ContactForm from '@alfadormx/blocks/composite/ContactForm.astro';
import MapBlock from '@alfadormx/blocks/primitives/Map.astro';
---
<ContactForm
action={{ type: 'endpoint', url: 'https://formspree.io/f/demo-aside-left' }}
asidePosition="left"
>
<div slot="aside" class="flex flex-col gap-4">
<address class="not-italic">
Example Studio
<br />
Keizersgracht 1<br />
1015 CC Amsterdam
</address>
<MapBlock lat={52.37} lon={4.89} height="240px" title="Office location" />
</div>
</ContactForm>API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
| action | ContactFormAction | — | Submission target: `{ type: 'endpoint', url }` POSTs to a form service such as Formspree or Basin; `{ type: 'mailto', address }` opens the visitor's mail client. |
| fields | ContactFormField[] | — | Ordered fields; a provided list replaces the defaults (default: name, email, phone, subject, message). |
| defaultFieldConfig | LayerConfig<Pick<FieldBaseProps, 'size' | 'intent' | 'shape' | 'hideLabel'>> | — | Layer merged under every field: size, intent, shape and hideLabel. |
| headline | HeadlineProps | — | Configuration for the Headline above the form (default: htmlTag 'h2'). |
| container | ContainerProps | — | Configuration for the outer Container. |
| submitButton | Omit<ButtonProps, 'type' | 'href' | 'as'> | — | Configuration for the submit Button (default: { label: 'Send', variant: 'solid', intent: 'primary' }). |
| successMessage | string | 'Thanks, your message has been sent.' | Message shown and focused after a successful send. |
| errorMessage | string | 'Your message could not be sent. Please try again.' | Message shown and focused when the send fails; the values are kept. |
| mailtoMessage | string | 'Your mail app should open with the message ready to send.' | Notice shown and focused after the mail client is opened (mailto mode only). |
| honeypot | string | false | '_gotcha' | Name of the hidden spam-trap field; `false` removes it. Formspree drops submissions that fill `_gotcha` (default: '_gotcha'). |
| formClass | string | — | Classes on the `<form>` element. |
| asidePosition | 'left' | 'right' | 'right' | Side the `aside` slot sits on; used only when the slot has content. |
| asideClass | string | — | Classes on the wrapper around the `aside` slot. |
| twoColumnContainer | TwoColumnContainerProps | — | Configuration for the TwoColumnContainer used when the `aside` slot has content (default: { htmlTag: 'div', responsive: true, content: { air: 'none' } }). |