ContactForm block renders a split-layout section with introductory copy on the left and a dynamic form on the right. Fields are driven by a referenced form document in Sanity, allowing editors to configure field types, labels, and choices without code changes. Submissions are processed by an Astro Action with server-side Zod validation and Cloudflare Turnstile bot protection.
Props
Optional heading above the description. Rendered as
<h2> at 3xl–4xl.Supporting copy shown below the heading in the left column.
Message displayed inside the form panel after a successful submission. Defaults to
"Thank you for your inquiry. We will get back to you shortly." if not set.A reference to a
form document. Required — Studio validates that a form is selected. The referenced document provides the field definitions, submit button label, and form ID used in the Astro Action.Background colour token. Defaults to
white.Vertical padding override. Defaults to
default.Content container max-width. Defaults to
default.Additional CSS classes.
HTML
id for anchor targeting.Form Field Types
The referencedform document defines fields using the formField object type. Each field maps to an AutoForm input via the following type mapping:
Sanity type | Rendered as |
|---|---|
text | <input type="text"> |
email | <input type="email"> |
tel | <input type="tel"> |
number | <input type="number"> |
textarea | <textarea rows={5}> |
select | <select> with choice options |
radio | Radio group with choice options |
checkbox | <input type="checkbox"> |
Usage in Sanity Studio
- First, create a Form document in the Forms section of the Studio sidebar. Define each field (label, type, name, required, placeholder, and choices for select/radio).
- Add a Contact Form block to a page.
- Set an optional Heading and Description for the left column copy.
- In the Form field, select the form document you created.
- Optionally set a custom Success Message.
Submission Flow
The form submission is handled entirely client-side via Astro Actions:- Client-side validation runs first (required fields, email format).
actions.submitForm(formData)is called — the hiddenform_idfield routes to the correct form record.- The Cloudflare Turnstile token is included in the form data for server-side verification.
- On success, the form panel transitions to the success state (
data-form-state="success") and a GTM eventform_submitis pushed towindow.dataLayer. - On error, field-level ARIA error attributes are applied and focus is moved to the first invalid field.
Variants / Options
This block has novariant field. The layout is always SectionSplit — copy left, form right.