# Registration, tour and contact forms

Source: https://help.ruuster.com/idx/recipe-forms

> The tour, contact and registration forms for your listing, agent and sign-up pages, posting to your own server route, which sends each lead to Follow Up Boss, Sierra Interactive or Sure Send.

Three forms from `@ruuster/idx-recipes` turn visitors into leads in your CRM. `TourForm` sits on each
listing page, `ContactForm` on your agent pages, and `RegistrationForm` on a sign-up page for
new-listing emails. Each one posts the visitor's details as JSON to your own server route, which
checks them and sends them to Follow Up Boss, Sierra Interactive or Sure Send with the listing
attached. Your CRM keys stay on your server.

## What the visitor sees

<figure class="idx-shot"><img src="/idx-docs/screens/ours/contact-form-1440.png" alt="Contact form (no listing), on a desktop (1440 px wide)" width="1440" height="900" loading="lazy" decoding="async"><figcaption>The contact form, as it sits in a listing page's sidebar.</figcaption></figure>

<figure class="idx-shot"><img src="/idx-docs/screens/ours/contact-form-375.png" alt="Contact form (no listing), on a phone (375 px wide)" width="375" height="812" loading="lazy" decoding="async"><figcaption>The contact form, as it sits in a listing page's sidebar.</figcaption></figure>

The markup is `static/html/contact-form.html` in `@ruuster/idx-recipes`. The [HTML and CSS recipe](https://help.ruuster.com/idx/recipe-html-css) shows how to fill it and which stylesheet and script to load.

<figure class="idx-shot"><img src="/idx-docs/screens/ours/mobile-bar-1440.png" alt="The bar fixed to the bottom of the listing page under 992px, on a desktop (1440 px wide)" width="1440" height="900" loading="lazy" decoding="async"><figcaption>On a phone, the contact and tour buttons stay at the bottom of the screen.</figcaption></figure>

<figure class="idx-shot"><img src="/idx-docs/screens/ours/mobile-bar-375.png" alt="The bar fixed to the bottom of the listing page under 992px, on a phone (375 px wide)" width="375" height="812" loading="lazy" decoding="async"><figcaption>On a phone, the contact and tour buttons stay at the bottom of the screen.</figcaption></figure>

The markup is `static/html/mobile-bar.html` in `@ruuster/idx-recipes`. The [HTML and CSS recipe](https://help.ruuster.com/idx/recipe-html-css) shows how to fill it and which stylesheet and script to load.

Each form has your consent sentence beside a box that starts unchecked, and the submit button stays
off until the visitor checks it. The registration and tour forms can carry a second, separate box for
listing alerts, also unchecked. Show that box only when your CRM, or AI Nurture on the Ruuster
Platform, sends listing emails. With the Listing Alerts add-on, use the
[Email me new matches](/idx/recipe-save-search) form instead. Leave `alertsConsentText` out
and the box is gone. A hidden field catches bots. On success the form shows your thank-you
text and pushes the GA4 `generate_lead` event.

Each lead also carries where the visitor came from: the visit's UTM values and ad click ids
(`gclid`, `fbclid`, `msclkid`), the first page of the visit and the outside page it came from, the
page the form was sent from, and the first and latest visit this browser remembers. Your route
passes all of it to your CRM. Two optional props add more:

- `agent`: the agent to assign the lead to, as `{ id, email, name }` (their CRM user id, email or
  full name). Use it on an agent's own page. Leave it out to let your CRM's routing assign the lead.
- `leadType`: `"buyer"`, `"seller"` or `"both"`, for example `leadType="seller"` on a home value
  form.

```tsx
<ContactForm action="/api/leads/fub" consentText={CONTACT_CONSENT} agent={{ id: "12", email: "pat@peachrealty.com", name: "Pat Agent" }} />
```

## What the page calls

| When | Request | Where it goes |
|---|---|---|
| The visitor submits a form | `POST /api/leads/fub` with the form's JSON | your own route, on your server |
| Your route accepts it | the CRM's own API | Follow Up Boss, Sierra Interactive or Sure Send |
| A tour or listing question | `GET /v1/listings/{listingId}` with your secret key | the listing's address, MLS number and price for the CRM |

The forms make no Ruuster API call themselves. `LEADS_ACTION` in `lib/site.ts` names the route;
change it to `/api/leads/sierra` or `/api/leads/suresend` for those CRMs.

## Steps

1. Pick your CRM's page and follow it to the end: [Follow Up Boss](https://help.ruuster.com/idx/crm-follow-up-boss),
   [Sierra Interactive](https://help.ruuster.com/idx/crm-sierra) or [Sure Send](https://help.ruuster.com/idx/crm-sure-send).
   It adds the route, the keys and `lib/crm.ts`.
2. Set `LEADS_ACTION` in `lib/site.ts` to your CRM's route, and write your own consent sentences in
   `CONSENT_TEXT` and `ALERTS_CONSENT_TEXT` ([Privacy and consent](https://help.ruuster.com/idx/privacy-consent)).
3. Put `TourForm` in the listing page's sidebar ([Listing detail page](https://help.ruuster.com/idx/recipe-listing-detail)),
   `ContactForm` on your agent pages ([One agent's listings](https://help.ruuster.com/idx/recipe-agent-listings)),
   and `RegistrationForm` on a sign-up page as below.
4. Send a test lead from a listing page and find it in your CRM, as your CRM's page describes.

## The code

Your settings, including the consent wording and the route:

<p class="code-title"><code>lib/site.ts</code></p>

```ts
// Your site's own settings. Every page, form and sitemap reads them from here.
import type { DetailAgent } from "@ruuster/idx-recipes";

/** Your brokerage's name as visitors see it. It is also the lead source your CRM shows. */
export const SITE_NAME = process.env.SITE_NAME || "Your Brokerage";

/** Your site's origin, with no trailing slash, for canonical URLs, sitemaps and pageHref. */
export const SITE_ORIGIN = (process.env.SITE_ORIGIN || "http://localhost:3000").replace(/\/+$/, "");

/** Where every form posts its lead: your own server route, which sends it to your CRM. */
export const LEADS_ACTION = "/api/leads/fub";

/** Your search page. The listing page's Back link and its X return here. */
export const SEARCH_PATH = "/search";

/** Your listing page URL template. The API builds each card's href from it. */
export const DETAIL_HREF = "/homes/{slug}";

/** A collection you curate in Ruuster for the homepage strip. Leave it null to show your own listings. */
export const FEATURED_COLLECTION_ID: string | null = null;

/** The consent sentence beside the contact box on every form. Edit it with your own wording. */
export const CONSENT_TEXT = `I agree that ${SITE_NAME} may contact me by phone, text or email about this request.`;

/** The consent sentence beside the separate listing-alerts box. */
export const ALERTS_CONSENT_TEXT = "Email me new listings like this one. I can unsubscribe at any time.";

/**
 * The agent or office your listing pages offer for questions and tours: the contact card, the
 * mobile action bar and the contact form are about this person. Use your own agent or your office's
 * team inbox, never the listing agent from the MLS. Leave a value unset and the page leaves that
 * line out; with no name, the buttons read "Contact an agent".
 */
export const SITE_AGENT: DetailAgent = {
  name: process.env.SITE_AGENT_NAME || null,
  photoUrl: process.env.SITE_AGENT_PHOTO_URL || null,
  phone: process.env.SITE_AGENT_PHONE || null,
  email: process.env.SITE_AGENT_EMAIL || null,
  license: process.env.SITE_AGENT_LICENSE || null,
  brokerage: SITE_NAME,
};

/** An absolute URL on your site for a path such as "/homes/123-main-st-…". */
export function absoluteUrl(path: string): string {
  if (/^https?:\/\//i.test(path)) return path;
  return `${SITE_ORIGIN}${path.startsWith("/") ? "" : "/"}${path}`;
}
```

A sign-up page with the registration form:

<p class="code-title"><code>app/alerts/page.tsx</code></p>

```tsx
// /alerts: a sign-up page for new-listing emails. The RegistrationForm posts to your own lead route,
// which creates the person in your CRM; the alerts box is separate from the contact box, and both start unchecked.
import { RegistrationForm } from "@ruuster/idx-recipes";
import { ALERTS_CONSENT_TEXT, CONSENT_TEXT, LEADS_ACTION, SITE_NAME } from "@/lib/site";

export const metadata = {
  title: `Get new listings by email · ${SITE_NAME}`,
  description: `Sign up with ${SITE_NAME} to hear about new homes for sale.`,
  alternates: { canonical: "/alerts" },
};

export default function AlertsPage() {
  return (
    <main>
      <h1>Get new listings by email</h1>
      <p>Tell us where you are looking, and we will send you new homes as they come on the market.</p>
      <RegistrationForm
        action={LEADS_ACTION}
        consentText={CONSENT_TEXT}
        alertsConsentText={ALERTS_CONSENT_TEXT}
        submitLabel="Sign up"
        successText="Thank you. Watch your inbox for new listings."
      />
    </main>
  );
}
```

The Follow Up Boss route the forms post to:

<p class="code-title"><code>app/api/leads/fub/route.ts</code></p>

```ts
// POST /api/leads/fub: the registration, tour and contact forms post here. lib/crm.ts does the work.
import { idx } from "@/lib/idx";
import { handleLead } from "@/lib/crm";

export const runtime = "nodejs";

export async function POST(request: Request): Promise<Response> {
  return handleLead(request, "fub", {
    env: process.env,
    getListing: async (listingId) => {
      const r = await idx.get(listingId);
      return r.ok ? r.data : null;
    },
  });
}
```

## Forms and your CRM

[Your CRM](https://help.ruuster.com/idx/crm-overview) explains the whole loop: your form, your route,
your CRM, and what Ruuster picks up from a connected CRM. [AI Nurture tags](https://help.ruuster.com/idx/crm-ai-nurture)
covers the alerts box, and [Another CRM](https://help.ruuster.com/idx/crm-other) shows how to send to
any other CRM from the same route.

## Rules this page follows

**MUST**

- Start both consent boxes unchecked, and send `consent.contact` and `consent.alerts` exactly as the
  visitor left them.
- Post to your own server route, and keep every CRM key on your server.
- Use your site's name as the lead source.
- Leave the street out of the CRM payload for a listing whose address is hidden (the CRM helpers do
  it).

**NEVER**

- Call a CRM from the browser.
- Put a form on results, area or sold pages: forms belong on listing pages, agent pages and your own
  sign-up page.

## Test it

Open a listing page, fill in the tour form with your own name and an email address you can check,
check the consent box and submit. The form shows your thank-you text. Find the new person in your CRM
with the listing attached and your site's name as the source. Then submit once more with the consent
box unchecked: the button stays off.

## Build it with AI

```text
Read RUUSTER_IDX.md first and follow its MUST and NEVER rules. Ask me if it doesn't cover something.

Send my site's leads to my CRM, following <https://help.ruuster.com/idx/recipe-forms> and the page for my CRM: <https://help.ruuster.com/idx/crm-follow-up-boss>, <https://help.ruuster.com/idx/crm-sierra> or <https://help.ruuster.com/idx/crm-sure-send>. My CRM is: [Follow Up Boss, Sierra Interactive or Sure Send]. Wire the TourForm, ContactForm and RegistrationForm components to my own server route, which validates the submission, drops it when the honeypot is filled, requires the contact consent box, and sends it with the @ruuster/idx/crm helpers. The consent box and the separate alerts box start unchecked. The lead source is SITE_NAME.

Use these environment variables: SITE_NAME, SITE_ORIGIN and my CRM's keys (FUB_API_KEY, FUB_SYSTEM, FUB_SYSTEM_KEY and FUB_COOKIE_SECRET for Follow Up Boss, SIERRA_API_KEY for Sierra Interactive, SURESEND_API_KEY for Sure Send). CRM keys stay on the server. Never paste a secret key or a CRM key into a chat, and never put one in browser code, a URL or a log.

Each route answers the form with a full sentence it can show, as the messages table on <https://help.ruuster.com/idx/crm-overview> does: 200 when sent, 403 from another site, 400 for a body it can't read, 422 for a missing contact or consent, 429 with Retry-After when the CRM asks to wait, 500 when a key or SITE_NAME is missing, and 502 when the CRM refuses. For Follow Up Boss, also build the listing-view route (POST /api/activity/fub with the ReportListingView component on the listing page), which sends one Viewed Property per registered visitor, listing and day. For Sierra Interactive and Sure Send there is no listing-view route.

When you are done, walk me through sending one test lead from a listing page and finding it in my CRM.
```

On a site without React, such as PHP, Python, Ruby on Rails, Go or plain HTML, [Build without React: HTML, CSS and JavaScript](https://help.ruuster.com/idx/recipe-html-css) gives you the same markup, the stylesheet and the script for every widget.
