Embed a form on your website with one script tag
Paste one script tag where you want the form. Set data-form to your form's slug. The script adds an iframe. It keeps the height in step with the form. It works on any page that lets you add HTML.
The snippet
<script src="https://aiformapi.com/embed.js" data-form="k3p9x2m7qa"></script>Replace k3p9x2m7qa with your form's slug. The slug is the last part of the public link: in https://aiformapi.com/f/k3p9x2m7qa it is k3p9x2m7qa. The slug also comes back when you create a form.
The dashboard shows the right snippet on the form page, with a copy button. Use that one if your forms are on a different host later.
Attributes
| Attribute | Needed | What it does |
|---|---|---|
data-form | Yes | The slug of the form. |
data-title | No | The title of the iframe, which screen readers read out. The default is Form. |
data-origin | No | The address that serves the form, such as https://aiformapi.com. The default is the address the script was loaded from. Set it only if the script and the forms are on different hosts. |
A complete page
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Join us on Friday</title>
</head>
<body>
<main style="max-width: 640px; margin: 2rem auto; padding: 0 1rem;">
<h1>Friday dinner</h1>
<p>Tell us if you can come.</p>
<script src="https://aiformapi.com/embed.js" data-form="k3p9x2m7qa"></script>
</main>
</body>
</html>How it behaves
- The script inserts an iframe right after the script tag.
- The iframe shows the form from AI Form API. It is not a copy, so changes you make to the form show up at once.
- The height adjusts to fit the form.
- Answers go to AI Form API. Your page does not see them.
Other ways to share a form
| Way | When to use it |
|---|---|
| The public link | Email, chat, QR code, social posts. |
| The embed script | You want the form inside your own page. |
| The API | You build your own screen. Read the schema with GET /v1/public/forms/{slug} and send answers to POST /v1/public/forms/{slug}/responses. Both paths are in openapi.json. |
Let visitors use their own AI agent
Agent fill is a form setting. Open your embedded page and check how it looks before you publish. If you want the same idea on a form that you built yourself, see agent-fill.js.