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

basic
---
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.

Interests
custom-fields
---
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.

shared-config
---
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.

mailto
---
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.

Example Studio
Keizersgracht 1
1015 CC Amsterdam
  • Mon–Fri: 9:00–17:00
  • Sat–Sun: closed
aside
---
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.

Example Studio
Keizersgracht 1
1015 CC Amsterdam
aside-left
---
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

PropTypeDefaultDescription
actionContactFormAction—Submission target: `{ type: 'endpoint', url }` POSTs to a form service such as Formspree or Basin; `{ type: 'mailto', address }` opens the visitor's mail client.
fieldsContactFormField[]—Ordered fields; a provided list replaces the defaults (default: name, email, phone, subject, message).
defaultFieldConfigLayerConfig<Pick<FieldBaseProps, 'size' | 'intent' | 'shape' | 'hideLabel'>>—Layer merged under every field: size, intent, shape and hideLabel.
headlineHeadlineProps—Configuration for the Headline above the form (default: htmlTag 'h2').
containerContainerProps—Configuration for the outer Container.
submitButtonOmit<ButtonProps, 'type' | 'href' | 'as'>—Configuration for the submit Button (default: { label: 'Send', variant: 'solid', intent: 'primary' }).
successMessagestring'Thanks, your message has been sent.'Message shown and focused after a successful send.
errorMessagestring'Your message could not be sent. Please try again.'Message shown and focused when the send fails; the values are kept.
mailtoMessagestring'Your mail app should open with the message ready to send.'Notice shown and focused after the mail client is opened (mailto mode only).
honeypotstring | false'_gotcha'Name of the hidden spam-trap field; `false` removes it. Formspree drops submissions that fill `_gotcha` (default: '_gotcha').
formClassstring—Classes on the `<form>` element.
asidePosition'left' | 'right''right'Side the `aside` slot sits on; used only when the slot has content.
asideClassstring—Classes on the wrapper around the `aside` slot.
twoColumnContainerTwoColumnContainerProps—Configuration for the TwoColumnContainer used when the `aside` slot has content (default: { htmlTag: 'div', responsive: true, content: { air: 'none' } }).