Concrete
GuidesAdd interactivity

Add a lead form

The page has to capture an enquiry — a name, an email and a message that reach the platform as a lead.

Goal

A contact section whose form submits a lead to the platform from the published page, and says so safely everywhere else.

Prerequisites

Steps

Write the form island

A form is state, an event handler and a network call, so all of it belongs to an island. submitLead is the one way to send one: it wraps the whole ingest contract — signing, the idempotency key, source attribution, retries and the size limit — and a hand-built request would break the day either half moves.

sections/LeadForm.tsx
"use client";

import type { IslandEditor } from "@homepages/concrete";
import { submitLead } from "@homepages/concrete/browser";
import { useState } from "react";

// Not live: inside the editor canvas the form stays its server-rendered first
// frame, so an author clicking around their own page never submits anything.
export const editor = { live: false } satisfies IslandEditor;

type Status = "idle" | "sending" | "sent" | "simulated" | "error";

// `FormData.get()` returns a string OR a File. Coercing with String() would send
// "[object File]" as the visitor's email; narrow instead.
function fieldText(form: FormData, key: string): string {
  const value = form.get(key);
  return typeof value === "string" ? value : "";
}

export default function LeadForm() {
  const [status, setStatus] = useState<Status>("idle");
  const [error, setError] = useState("");

  if (status === "sent" || status === "simulated") {
    return <p role="status">{status === "simulated" ? "Preview only — no lead was sent." : "Thanks — we'll be in touch."}</p>;
  }
  return (
    <form
      onSubmit={(event) => {
        event.preventDefault();
        const form = new FormData(event.currentTarget);
        setStatus("sending");
        void submitLead({
          email: fieldText(form, "email"),
          name: fieldText(form, "name"),
          message: fieldText(form, "message"),
          extra: { form_context: "contact-section" },
        }).then((result) => {
          if (result.ok) {
            setStatus(result.simulated === true ? "simulated" : "sent");
            return;
          }
          setError(result.message);
          setStatus("error");
        });
      }}
    >
      <label>
        Email
        <input name="email" type="email" required autoComplete="email" />
      </label>
      <label>
        Message
        <textarea name="message" rows={3} />
      </label>
      <button type="submit" disabled={status === "sending"}>
        {status === "sending" ? "Sending…" : "Send"}
      </button>
      {status === "error" ? <p role="alert">{error}</p> : null}
    </form>
  );
}

submitLead never throws — inspect what it resolves to. email is the only required field; name, phone and message are optional and extra carries whatever else the form collects, verbatim and unable to shadow the named fields.

Three outcomes, not two

A submission resolves as accepted, as { ok: true, simulated: true }, or as a failure carrying a message written for the visitor. Simulated is what happens wherever there is no published site config — the editor canvas, concrete dev, any local preview: nothing is sent, and the result says so rather than failing. Branch on it in the confirmation copy, as the island above does, so a preview never claims a lead was captured.

Place it in a section

sections/contact.tsx
import { fact, fill, Section, section, Slot, text } from "@homepages/concrete";
import type { ReactNode } from "react";

// import LeadForm from "./LeadForm";
declare const LeadForm: () => ReactNode;

export const Contact = section(
  {
    key: "contact",
    label: "Contact",
    slots: {
      heading: text.medium({
        label: "Heading",
        cap: 60,
        source: fill.write({
          reads: [fact.property.address],
          brief: "Invite the reader to ask about this property, in under 60 characters. Write one sentence. Write in the second person, addressing the reader. Plain and direct.",
        }),
      }),
    },
  },
  ({ slot, nav }) => (
    <Section id={nav.selfAnchor}>
      <Slot.Text slot={slot.heading} as="h2" />
      <LeadForm />
    </Section>
  ),
);

Place Contact on the home page beside the hero, and give it a content entry in the fixture so the heading is not empty while you work.

Verify

Run concrete check, then submit the form in concrete dev. It answers Preview only — no lead was sent: there is no site config on a preview page, which is exactly what makes the form safe to exercise while authoring. On a published page the same submission is sent, and an accepted lead is announced page-wide as LEAD_EVENT for whatever integrations the site has connected.

On this page