Request forms
A visitor leaves a request on the site: «Обратный звонок» (a callback), «Рассчитать стоимость» (an estimate), «Бронь столика» (a table booking). You describe the form and put it on a page. The CMS checks the request and mails it to the owner and to those the owner named. The CMS itself does not keep requests: once the letter is sent, the request is removed.
It needs @seamlet/astro 2.1 or newer.
1. Describe the form
Section titled “1. Describe the form”import { requestChoice, requestForm, requestLongText, requestPhone, requestText,} from "@seamlet/astro/schema";
export const estimateForm = requestForm({ id: "estimate", title: "Рассчитать стоимость", fields: { name: requestText({ label: "Имя", required: true }), phone: requestPhone({ label: "Телефон", required: true }), size: requestChoice({ label: "Размер", options: ["6×4", "6×6"] }), comment: requestLongText({ label: "Комментарий", maxLength: 1000 }), },});Fields:
requestText— a line (up to 200 characters unlessmaxLengthis set);requestLongText— several lines (up to 2000);requestPhone— a phone;requestEmail— an email; the owner replies to it right from the letter;requestChoice— one ofoptions.
Every field may be required. The form’s title names the request in the letter. The labels of the fields go into the data policy: «имя, телефон, размер, комментарий» (name, phone, size, comment).
2. Give the form to the CMS
Section titled “2. Give the form to the CMS”import { estimateForm } from "./forms";
export default defineSeamletSite({ schema, initialContent, pages, forms: [estimateForm],});The CMS learns about forms from the site’s description, as it does about the schema: a new form starts working after the site is deployed.
3. Put the form on a page
Section titled “3. Put the form on a page”---import RequestForm from "@seamlet/astro/components/RequestForm.astro";import { estimateForm } from "../forms";---
<RequestForm form={estimateForm} submitLabel="Рассчитать" />Props of RequestForm:
form— the form;submitLabel— the words of the button;submitMarker— the marker of the field the words of the button come from: then the owner edits them right on the page (package 2.4.0 and newer);sentTextandfailedText— what the visitor reads when the request was sent or was not;consentHref— the address of the consent to data processing,/consentof your site by default;policyHref— the address of the data policy,/privacyof your site by default;instance— tells apart two forms with oneidon one page.
The labels of the fields and the consent checkbox belong to the code: the labels are named in the form, the CMS labels the values in the letter by them, and the law sets the text of the consent. The component marks them data-cms-fixed, and the markup check does not list them. The button is marked so too unless submitMarker is given. To let the owner edit the words of the button, add a field for them and pass its marker:
---import RequestForm from "@seamlet/astro/components/RequestForm.astro";import { editable } from "@seamlet/astro/schema";import { estimateForm } from "../forms";import type { Content } from "../schema";
interface Props { content: Content;}
const { content } = Astro.props;const edit = editable<Content>();---
<RequestForm form={estimateForm} submitLabel={content.order.submit} submitMarker={edit("order", "submit")}/>Here the schema has a group order with a text submit: order: group({ label: "Заявка", fields: { submit: text({ label: "Кнопка" }) } }).
The component puts out plain elements with classes, and the styles are up to the site: seamlet-form, seamlet-form-field, seamlet-form-issue, seamlet-form-consent, seamlet-form-submit, seamlet-form-sent, seamlet-form-failed.
.contacts :global(.seamlet-form-field) { display: grid; gap: 0.25rem;}4. Consent and the data policy
Section titled “4. Consent and the data policy”The operator of the visitors’ personal data is the site’s owner; Seamlet only passes requests on by the owner’s commission. So both documents the Russian personal data law (Federal Law No. 152-ФЗ) requires are pages of the site itself, and the owner edits their text in the CMS like other texts:
/consent— the visitor’s consent. Since 1 September 2025 it is a document separate from the others;/privacy— the policy of personal data processing.
The form has a separate checkbox «Даю согласие на обработку персональных данных и принимаю политику их обработки» (“I consent to the processing of personal data and accept the policy of its processing”) with links to both pages. It is never checked in advance. The props consentHref and policyHref set other addresses.
The templates build the texts from the owner’s details and the fields of the forms. The policy is split into the sections Роскомнадзор (Roskomnadzor, the Russian data protection authority) recommends: purposes with the list of data, terms and the way of destruction, legal grounds, the way of processing and protection, answers to requests within the law’s terms. The owner fills in only their own details.
import { privacyConsentFields, privacyPolicyFields,} from "@seamlet/astro/schema";
export const schema = { // … privacy: privacyPolicyFields(), consent: privacyConsentFields(),};import { privacyConsentTextOf, privacyPolicyTextOf, type PolicySource,} from "@seamlet/astro/schema";import { estimateForm } from "./forms";
const policySource: PolicySource = { siteTitle: "Моя мастерская", operator: { name: "ИП Иванов Иван Иванович", inn: "000000000000", address: "г. Киров, ул. Примерная, д. 1", email: "hello@example.ru", }, forms: [estimateForm],};
export const initialContent: SiteContent = { // … privacy: { title: "Политика обработки персональных данных", text: privacyPolicyTextOf(policySource), }, consent: { title: "Согласие на обработку персональных данных", text: privacyConsentTextOf(policySource), },};One page renders either of the two documents:
---import RichText from "@seamlet/astro/components/RichText.astro";import { editable } from "@seamlet/astro/schema";import type { SiteContent } from "../schema";
interface Props { content: SiteContent; part: "privacy" | "consent";}
const { content, part } = Astro.props;const shown = content[part];const edit = editable<SiteContent>();---
<main {...edit(part)}> <h1 {...edit(part, "title")}>{shown.title}</h1> <div {...edit(part, "text")}> <RichText value={shown.text} /> </div></main>---import DocumentPage from "./DocumentPage.astro";
const { content } = Astro.props;---
<DocumentPage content={content} part="privacy" />ConsentPage.astro is the same, with part="consent". Add both pages to the site’s pages:
pages: { "/": { title: "Главная", component: HomePage }, "/privacy": { title: "Политика данных", component: PrivacyPage }, "/consent": { title: "Согласие на обработку данных", component: ConsentPage },},Your own code at the steps of sending
Section titled “Your own code at the steps of sending”Without a script the form is sent to the CMS as a plain POST, and the CMS answers with a page of its own with a link back. With the package’s script the visitor stays on the page: the script checks the fields with the same code as the CMS, shows issues under the fields and sends the request.
Your code hears every step through events on the form element (they bubble):
seamlet:request-send(REQUEST_SEND_EVENT) — before sending,detail: { form, entries }. It can be cancelled: afterevent.preventDefault()the package sends nothing, and the site sends the request itself.seamlet:request-sent(REQUEST_SENT_EVENT) — the CMS took the request,detail: { form, entries, id }. This is where an analytics goal or a message of your own goes.seamlet:request-failed(REQUEST_FAILED_EVENT) —detail: { form, reason, issues }, wherereasonisinvalid,closed(nobody to send requests to: the site has no address at all),too-manyorunavailable.
import { REQUEST_SENT_EVENT, type RequestSentDetail,} from "@seamlet/astro/schema";
document.addEventListener(REQUEST_SENT_EVENT, (event) => { const { form } = (event as CustomEvent<RequestSentDetail>).detail; ym(COUNTER_ID, "reachGoal", `request-${form}`);});If the site’s Content-Security-Policy has connect-src or form-action, add the CMS’s address to both directives. A request the policy stops on its way the browser sends as a plain form.