Form integration
Add a form to your website
Two lines of HTML put a working form on any page. This guide covers where to get the code, every option, how to use it in popular frameworks and site builders, how to style it, and what to check when something goes wrong.
Get your embed code
- Sign in to the dashboard and open Forms.
- Open a form and switch to the Settings tab.
- In Embed on your website, copy the snippet. Your public key is already in it.
The same section lets you restrict the form to certain websites, change the button text and theme colour, and rotate the public key. See the Dashboard guide.
Basic embed
<div data-inputdock="pk_your_public_key"></div>
<script src="https://cdn.inputdock.com/v1/embed.js" async></script>- The
divis where the form appears. Put it anywhere in the page body. - The script can sit before or after the
div. It waits for the page to finish loading and then finds every placeholder. - You can place several
divs, each with its own key, on one page. One failing form does not stop the others. - Include the script once per page, however many forms there are.
Options
Every option is optional. Set them as data- attributes on the element:
<div
data-inputdock="pk_your_public_key"
data-theme="dark"
data-accent="#8ac926"
data-radius="12"
data-values='{"ref":"pricing-page"}'
data-css="/my-form.css"
></div>
<script src="https://cdn.inputdock.com/v1/embed.js" async></script>| Attribute | Example | Description |
|---|---|---|
data-inputdock | pk_… | Required. The form’s public key. Marks the element the form is drawn into. |
data-theme | light | dark | auto | Colour scheme. Defaults to light; auto follows the visitor’s system setting. |
data-accent | #8ac926 | Accent colour. Overrides the theme colour set on the form in the dashboard. |
data-radius | 12 | Corner radius. A plain number is pixels; a CSS length such as 0.5rem also works. |
data-values | {"ref":"x"} | JSON object of prefilled values, keyed by field name. Also how hidden fields get their value. |
data-css | /my-form.css | URL of a stylesheet loaded inside the form. Must start with https://, http:// or /. |
Appearance set here wins over the form’s own theme colour from the dashboard. Everything else about the form (fields, button text, thank-you screen) is managed in the dashboard and updates without touching your page.
Changes you save in the dashboard reach embedded forms within about a minute, because the form definition is cached briefly.
Frameworks and site builders
Plain HTML
Use the basic embed as it is.
React
Load the script once, then mount into a ref. InputDock.mount ignores an element that is already mounted, so effects that run twice in development are safe.
import { useEffect, useRef } from 'react'
const SCRIPT = 'https://cdn.inputdock.com/v1/embed.js'
export function InputDockForm({ publicKey, theme = 'auto' }) {
const ref = useRef(null)
useEffect(() => {
const mount = () => window.InputDock.mount(ref.current, { key: publicKey, theme })
if (window.InputDock) return mount()
let script = document.querySelector('script[src="' + SCRIPT + '"]')
if (!script) {
script = document.createElement('script')
script.src = SCRIPT
script.async = true
document.head.append(script)
}
script.addEventListener('load', mount, { once: true })
}, [publicKey, theme])
return <div ref={ref} />
}Next.js
The simplest route is a placeholder plus next/script:
// app/contact/page.tsx (Next.js App Router)
import Script from 'next/script'
export default function ContactPage() {
return (
<>
<div data-inputdock="pk_your_public_key" data-theme="auto" />
<Script src="https://cdn.inputdock.com/v1/embed.js" strategy="afterInteractive" />
</>
)
}For client-side navigation between pages, use the React component above so the form mounts on each visit.
Astro
---
// src/pages/contact.astro
---
<div data-inputdock="pk_your_public_key" data-theme="auto"></div>
<script is:inline src="https://cdn.inputdock.com/v1/embed.js" async></script>is:inline stops Astro from bundling the script, so the CDN file is used as-is.
Vue
<script setup>
import { onMounted, ref } from 'vue'
const el = ref(null)
onMounted(() => {
const mount = () => window.InputDock.mount(el.value, { key: 'pk_your_public_key' })
if (window.InputDock) return mount()
const script = document.createElement('script')
script.src = 'https://cdn.inputdock.com/v1/embed.js'
script.async = true
script.onload = mount
document.head.append(script)
})
</script>
<template><div ref="el"></div></template>WordPress
In the block editor add a Custom HTML block where the form should appear and paste the two lines. If your theme or a security plugin strips <script> tags from content, add the script to the theme footer (or a header and footer plugin) and keep only the div in the post.
Webflow
Add an Embed element (Add panel, Components) where the form should go and paste the snippet. Custom code only runs on the published site, not in the designer preview.
Shopify
Add a Custom Liquid section or block to the page in the theme editor and paste the snippet. For a form that appears on several templates, put the script tag in theme.liquid just before </body> and keep the div in the sections where it is needed.
Single-page apps, modals and tabs
The script exposes window.InputDock with two functions:
InputDock.mount(element, options)draws a form into one element. Options:key,api,theme,accent,radius,values,css. Anything you leave out falls back to the element’sdata-attribute.InputDock.mountAll(scope)mounts every unmounted[data-inputdock]insidescope(the whole document by default).
// Mount into any element, any time: a modal, a tab, a route change.
const el = document.querySelector('#contact')
InputDock.mount(el, {
key: 'pk_your_public_key',
theme: 'dark',
accent: '#8ac926',
radius: '12',
values: { ref: 'pricing-page' },
})
// Or pick up new [data-inputdock] placeholders added after page load:
InputDock.mountAll(document.querySelector('#drawer'))An element is only ever mounted once. To show a different form, use a new element.
Prefill and hidden fields
Pass data-values (or values in mount) with field names as keys. Visitors see prefilled values and can edit them. Hidden fields are never shown, so they are the right place for things like the page the visitor came from, a campaign tag or a plan name; their value always comes from values.
Use the field’s Name from the builder as the key. Checkbox groups take an array, a single checkbox takes true or false, and star ratings take a number string such as "4".
Styling
The form lives in a Shadow DOM, so rules in your page’s stylesheet do not reach into it. You have three ways to change how it looks:
- Theme, accent and radius with
data-theme,data-accentanddata-radius, or the theme colour set on the form in the dashboard. - CSS variables set on the placeholder element from your own CSS:
[data-inputdock] {
--id-accent: #8ac926; /* buttons, focus rings, highlights */
--id-radius: 12px; /* corner radius */
--id-bg: transparent; /* form background */
--id-text: #111827; /* text */
--id-muted: #6b7280; /* help text */
--id-border: #d1d5db; /* input borders */
--id-surface: #ffffff; /* input background */
--id-danger: #dc2626; /* error messages */
}- A stylesheet inside the form. Give a field a CSS class in the builder (Advanced section, paid forms only), then style that class in a file you point
data-cssat.
/* /my-form.css: loaded inside the form's Shadow DOM */
.my-rounded-input { border-radius: 999px; }
.my-big-button { font-size: 1.1rem; }
/* Colours are CSS variables, so you can also set them on the element
from your own page CSS: */
/* [data-inputdock] { --id-bg: #101828; --id-text: #f9fafb; } */After the visitor submits
What happens next is configured per form in the dashboard, under Thank-you screen: a title and message, an optional button with a link, an optional redirect to another page after a delay, and whether visitors may submit another response. With nothing configured, visitors see “Thank you! Your response has been submitted.”
To react in your own code, for example to fire an analytics conversion, listen for events.
Events
The widget dispatches DOM events from your placeholder element. They bubble, so you can also listen on document.
| Event | When | event.detail |
|---|---|---|
inputdock:ready | The form loaded and rendered. | none |
inputdock:submitted | The submission was accepted. | { id }, the submission id |
inputdock:error | Loading or sending failed. | { status, message }; status is 0 when the server could not be reached |
const el = document.querySelector('[data-inputdock]')
el.addEventListener('inputdock:ready', () => {
console.log('form is visible')
})
el.addEventListener('inputdock:submitted', (event) => {
console.log('saved as submission', event.detail.id)
// e.g. send a conversion event to your analytics
})
el.addEventListener('inputdock:error', (event) => {
console.warn(event.detail.status, event.detail.message)
})Allowed websites
By default a public key works from any website. To limit it, list your sites under Allowed websites in the form’s Settings. Each entry is an origin: scheme, host and optional port, with no path.
https://www.example.comallows exactly that site.https://*.example.comallows any subdomain, but notexample.comitself. Add both if you need both.- You can list up to 20.
The check uses the browser’s Origin header, so it stops other websites from embedding your form, but it is not a defence against someone calling the API directly. The built-in spam protection covers that case. If a form has allowed websites, requests with no Origin are rejected.
Content Security Policy
If your site sends a CSP header, allow the script origin and the API:
Content-Security-Policy:
script-src 'self' https://cdn.inputdock.com;
connect-src 'self' https://api.inputdock.com;Troubleshooting
| Symptom | Likely cause and fix |
|---|---|
| Nothing appears | The script did not load or the element has no key. Check the browser console and network tab, and that the element has a non-empty data-inputdock attribute. |
| “This form is not available” or 404 | The public key is wrong, was rotated, or the form is inactive or its subscription has expired. Copy the snippet again from the form’s Settings tab. |
| 403 “This site is not allowed to use this form” | The form lists allowed websites and your page’s origin is not among them. Add it, including the scheme and port, for example https://www.example.com. |
| Submit does nothing or the browser blocks it | A Content Security Policy is blocking the script or the API request. Allow both (see below). |
| Submission accepted but never arrives | Very fast submissions (under 1.5 seconds after the form appeared) and filled honeypot fields are silently dropped as bots. Test like a person, not a script. |
| 429 Too many requests | A visitor can submit a form 10 times per minute, and a form accepts 1,000 submissions per day. See the API reference for all limits. |
| 422 with field errors | The answers failed validation. The widget shows each message next to its field. |
Posting from your own server instead? That path uses the private key and has different limits. See the API reference.