Astro
A .astro page with the plain HTML form and a redirect to /thanks, or the hosted embed with is:inline. Zero client JavaScript apart from Turnstile.
Sample: samples/astro (src/pages/contact.astro, contact-embed.astro, thanks.astro, README). Any adapter; static output is fine.
The snippet
---
const formId = import.meta.env.PUBLIC_CONTACTUSIQ_FORM_ID ?? 'au_xxxxxxx';
const turnstileSiteKey = import.meta.env.PUBLIC_TURNSTILE_SITE_KEY ?? '0x4AAAAAAA_PLACEHOLDER';
const thanksUrl = new URL('/thanks', Astro.site ?? 'https://example.com').href;
---
<form action={`https://api.contactusiq.com/s/${formId}`} method="POST">
<input name="name" type="text" required />
<input name="email" type="email" required />
<textarea name="message" required></textarea>
<input name="_honeypot" type="text" tabindex="-1" autocomplete="off" style="position:absolute;left:-10000px" />
<input type="hidden" name="_redirect" value={thanksUrl} />
<div class="cf-turnstile" data-sitekey={turnstileSiteKey}></div>
<button type="submit">Send</button>
</form>
<script is:inline src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>The hosted embed alternative:
<div id="contactusiq-form"></div>
<script is:inline src={`https://api.contactusiq.com/f/${formId}/embed.js`} data-target="#contactusiq-form" async defer></script>is:inline is required on both external scripts; without it Astro tries to bundle them.
Steps
- Copy the
.astrofiles intosrc/pages/. - Add
PUBLIC_CONTACTUSIQ_FORM_ID=au_xxxxxxxandPUBLIC_TURNSTILE_SITE_KEY=0x4AAAAAAA_PLACEHOLDERto.env, or edit the defaults at the top of each file. - Set
siteinastro.config.mjs(for examplesite: 'https://www.example.com') so_redirectbecomes an absolute URL; otherwise hard-code it. - Build and deploy on the verified domain. Visit
/contactor/contact-embed.
How to test
/contact: a 303 redirect to /thanks. /contact-embed: the form renders in the div and a submit returns 200 with {"ok":true,"id":"..."}.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
| Redirect goes to the wrong host | _redirect must be absolute. Check site in astro.config.mjs. |
| Redirected but nothing in the inbox | Origin mismatch: astro dev on localhost is not a verified domain. Test on the deployed site. |
Embed script 404 or missing | The script tag lacks is:inline, or the form id is wrong or unpublished. |