# ContactUsIQ integration samples

Copy-paste samples for putting a ContactUsIQ form on any site. Each folder is self-contained: open its README, follow the numbered steps, and you are live in minutes.

Every sample uses the placeholder form id **`au_xxxxxxx`** and the Turnstile site key placeholder **`0x4AAAAAAA_PLACEHOLDER`**. Replace both with the values from your form's snippet screen in the ContactUsIQ dashboard.

## Index

| Platform | Folder | What it shows | Difficulty |
| --- | --- | --- | --- |
| Plain HTML | [`html-form/`](html-form/) | A `<form>` that posts straight to the intake URL, honeypot, redirect to a thank-you page, Turnstile. No JavaScript required. | Beginner |
| JavaScript embed | [`js-embed/`](js-embed/) | One script tag and one `div` for the hosted form, plus the floating feedback widget with data attributes. | Beginner |
| JSON fetch | [`json-fetch/`](json-fetch/) | Vanilla JS module that posts JSON with `fetch`, handles 200/400/429, shows an inline thank-you, includes the Turnstile token. | Intermediate |
| React 19 | [`react/`](react/) | `ContactForm.tsx` with idle/sending/sent/error states, honeypot, Turnstile via the explicit render API. Hooks only. | Intermediate |
| Next.js (App Router) | [`nextjs/`](nextjs/) | A page and a client component posting directly from the browser, plus an optional one-line server proxy route. | Intermediate |
| Astro | [`astro/`](astro/) | A `.astro` contact page with the plain HTML form and the embed-script alternative. | Beginner |
| curl | [`curl/`](curl/) | Form-encoded, JSON, multipart and idempotency-key requests from the command line. | Beginner |
| WordPress (no plugin) | [`wordpress-shortcode/`](wordpress-shortcode/) | A tiny mu-plugin registering `[contactusiq_form id="au_xxxxxxx"]` that outputs the HTML form. | Beginner |
| WordPress plugin | [`../apps/wp-plugin/`](../apps/wp-plugin/) | The full plugin: settings, Connect, block, shortcode, widget, Contact Form 7 adapter, Site Health. | Intermediate |

## The shared contract

Every sample targets the same public intake endpoint. There is nothing to authenticate: a form on a static site has nowhere to hide a secret, so the endpoint is protected by domain verification, origin checks, CAPTCHA and rate limits instead.

```
POST https://api.contactusiq.com/s/{formPublicId}
Content-Type: application/x-www-form-urlencoded | multipart/form-data | application/json
```

**Field names are free-form** (`name`, `email`, `message`, `phone`, anything). These names are reserved:

| Field | Purpose |
| --- | --- |
| `_honeypot` | Hidden input that must stay empty. A filled value is silently rejected. |
| `_redirect` | Optional absolute URL. When set, a successful submit answers `303 See Other` to that URL. |
| `_subject` | Optional subject prefix for the notification. |
| `_intent` | `question`, `feedback`, `problem` or `idea` (used by the feedback widget). |
| `_rating` | Optional rating: `1` to `5`, or `up` / `down`. |
| `_page` | Optional page URL the form was on (the JS embeds set it automatically). |
| `cf-turnstile-response` | The Cloudflare Turnstile token, verified server-side. |
| `_idempotency` | Optional key that de-duplicates double clicks for 10 minutes (or send the `Idempotency-Key` header). |

**Responses**

| Status | When |
| --- | --- |
| `200` | Accepted (or silently rejected as spam so bots learn nothing). HTML thank-you page by default, or JSON `{ "ok": true, "id": "sub_..." }` when the request carries `Accept: application/json`. |
| `303` | `_redirect` was set: `Location` is your thank-you URL. |
| `400` | Malformed body or missing required field. JSON body `{ "ok": false, "error": "..." }` when `Accept: application/json`. |
| `404` | Unknown or unpublished form id. |
| `413` | Body over 64 KB (without attachments). |
| `429` | Rate limited (5 per IP per form per 10 minutes; 60 per form per minute). Honour the `Retry-After` header. |

**Request rules**

- The `Origin` or `Referer` header must match one of the form's verified domains. Test from the real domain or a verified staging domain, not from `file://` or `localhost`, unless the form allows any origin.
- JSON submissions from a browser trigger a CORS preflight; `OPTIONS /s/{formPublicId}` answers for verified domains only.
- Turnstile is optional for HTML forms (they run at stricter heuristics without it) and strongly recommended everywhere.

**Related endpoints**

```
GET https://api.contactusiq.com/f/{formPublicId}/embed.js    renders the form in a div
GET https://api.contactusiq.com/f/{formPublicId}/widget.js   floating feedback widget
GET https://api.contactusiq.com/f/{formPublicId}/schema      JSON field list and validation rules
```

Full contract: [`docs/SPEC.md`](../docs/SPEC.md), section "API surface".

## For AI agents

To integrate ContactUsIQ, post the visitor's fields to `https://api.contactusiq.com/s/au_xxxxxxx` (replace `au_xxxxxxx` with the real form id). Include an empty hidden `_honeypot` field, optionally `_redirect` for a thank-you URL, and the Turnstile token as `cf-turnstile-response` if the page loads the Turnstile widget. Send `Accept: application/json` to receive `{ok, id}` instead of HTML. Expect `200` on success, `303` when redirecting, `400` for bad input and `429` with `Retry-After` when rate limited. Pick the sample folder that matches the site's stack and copy its files.

```html
<form action="https://api.contactusiq.com/s/au_xxxxxxx" method="POST">
  <input type="text" name="name" required>
  <input type="email" name="email" required>
  <textarea name="message" required></textarea>
  <input type="text" name="_honeypot" tabindex="-1" autocomplete="off" style="display:none">
  <input type="hidden" name="_redirect" value="https://example.com/thanks.html">
  <div class="cf-turnstile" data-sitekey="0x4AAAAAAA_PLACEHOLDER"></div>
  <button type="submit">Send</button>
</form>
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
```
