# Embed a form on any website

A hipaaform.ai form is added to a page with two lines of HTML. The form itself runs in an isolated iframe served from `https://app.hipaaform.ai`, so answers never touch the host page, its scripts or its database.

## Quick start

Paste this where the form should appear, replacing `FORM_ID` with the ID shown on the form's **Share** tab:

```html
<div data-hipaaform="FORM_ID"></div>
<script src="https://app.hipaaform.ai/embed.js" async></script>
```

That is the whole integration. The loader finds every `data-hipaaform` element on the page, mounts an iframe in each one and keeps its height in sync with the form, so there are no scrollbars and no fixed heights to maintain.

- A form ID is 6 to 32 lowercase letters and digits, for example `k7m2xq9pd4tw`.
- The form must be **published** in the hipaaform.ai panel before it will load.
- Include the script once per page, even when the page has several forms.

## Options

| Attribute | Required | Description |
|---|---|---|
| `data-hipaaform` | Yes | The form ID. |
| `data-title` | No | Accessible title for the iframe, read by screen readers. Defaults to `Secure form`. |

```html
<div data-hipaaform="FORM_ID" data-title="New patient intake form"></div>
```

## Hosted link

Every published form also has a hosted page that needs no embed code. Use it in emails, text messages and QR codes:

```
https://app.hipaaform.ai/f/FORM_ID
```

Query parameters on the hosted link are captured as attribution, so `https://app.hipaaform.ai/f/FORM_ID?utm_source=newsletter` records `utm_source=newsletter` with the submission.

## Forms added after page load

Single-page apps and page builders often insert markup after the loader has run. Call `scan()` to mount any new `data-hipaaform` elements:

```js
window.hipaaform.scan();
```

Calling it again is safe: elements that are already mounted are skipped. Loading `embed.js` a second time has the same effect.

## Conversion events

When a visitor submits a form, the loader tells the host page. The signal carries the form ID only — never the answers.

A DOM event is dispatched on the embed element and bubbles to `document`:

```js
document.addEventListener('hipaaform:submit', (event) => {
  console.log('Form submitted:', event.detail.formId);
});
```

If the page uses Google Tag Manager (a `window.dataLayer` array exists), the loader also pushes:

```js
{ event: 'hipaaform_submit', hipaaform_id: 'FORM_ID' }
```

Create a Custom Event trigger named `hipaaform_submit` in Tag Manager to fire conversion tags. See [Attribution and conversion tracking](https://app.hipaaform.ai/docs/attribution) for the data captured with each submission.

## After submission

Each form shows either a thank-you message or redirects to a URL you choose in the form's settings. For an embedded form the redirect navigates the host page, not just the iframe.

## Restricting where a form can be embedded

By default a published form can be embedded on any site. On the form's **Share** tab you can list allowed domains (for example `www.yourpractice.com` or `*.yourpractice.com`); browsers will then refuse to display the form inside any other site. The hosted link always works.

## Content Security Policy

If the host site sends a Content Security Policy, allow the loader and the frame:

```
script-src https://app.hipaaform.ai;
frame-src https://app.hipaaform.ai;
```

## Troubleshooting

- **Nothing appears.** Check that the form is published, that the ID is correct, and that `embed.js` is loaded from `https://app.hipaaform.ai`.
- **"This form is not available".** The form was unpublished or the workspace is not active.
- **The frame is blocked.** The form has an allowed-domains list that does not include this site, or the site's own Content Security Policy blocks `https://app.hipaaform.ai`.
- **No JavaScript.** The form needs JavaScript. Offer the hosted link as a fallback inside a `<noscript>` element.
