Astro
Astro builds plain HTML, so there's nothing to run when a visitor presses Send. Point the form at BootForm and it is. Everything on this page works on a static Astro site as it is, with no adapter, no integration and nothing to install.
Basic form
Put the form straight into any page, for example src/pages/contact.astro. The examples leave out your layout (<html>, <head> and so on) to stay short:
---
// src/pages/contact.astro
---
<h1>Contact</h1>
<form action="https://f.bootform.com/{form_id}" method="POST">
<label for="email">Your email</label>
<input id="email" name="email" type="email" required>
<label for="message">Message</label>
<textarea id="message" name="message" required></textarea>
<input type="text" name="honeypot" style="position:absolute;left:-9999px" tabindex="-1" autocomplete="off">
<button type="submit">Send</button>
</form>Replace {form_id} with a UUID you generate yourself (the UUID generator gives you one). Send yourself a test message, then claim the form before the site goes live, so nobody else can claim your ID first.
The honeypot field is a spam trap: people never see it, bots fill it in. Keep it positioned off screen as shown, not hidden with hidden or display:none, which some bots know to skip. New forms use the name honeypot; if you renamed yours, use the name in your form's snippet. See Spam protection.
Keep the form ID in one file, and the form in a component
If the form appears on more than one page, or you might change it, keep the ID in one place:
// src/consts.ts
export const BOOTFORM_FORM_ID = '{form_id}'Then move the form into a component, src/components/ContactForm.astro, and import the ID:
---
// src/components/ContactForm.astro
import { BOOTFORM_FORM_ID } from '../consts'
---
<form action={`https://f.bootform.com/${BOOTFORM_FORM_ID}`} method="POST">
<label for="email">Your email</label>
<input id="email" name="email" type="email" required>
<label for="message">Message</label>
<textarea id="message" name="message" required></textarea>
<input type="text" name="honeypot" style="position:absolute;left:-9999px" tabindex="-1" autocomplete="off">
<button type="submit">Send</button>
</form>Use it on any page: import it between the --- lines at the top, then put the tag where the form was.
---
// src/pages/contact.astro
import ContactForm from '../components/ContactForm.astro'
---
<h1>Contact</h1>
<ContactForm />A thank-you page
By default, a successful submission shows the visitor BootForm's short "Thanks" page. To send them to a page of your own instead, add a _redirect field with the full URL. Build that URL in the component from your Astro config, so it is right on every page. Add two lines to the top of ContactForm.astro:
---
// src/components/ContactForm.astro
import { BOOTFORM_FORM_ID } from '../consts'
const base = import.meta.env.BASE_URL.replace(/\/$/, '')
const thanksUrl = new URL(`${base}/thanks/`, Astro.site)
---and one field inside the form, next to the honeypot:
<input type="hidden" name="_redirect" value={thanksUrl.href}>Then create the page it points at, src/pages/thanks.astro:
---
// src/pages/thanks.astro
---
<h1>Thanks</h1>
<p>Your message is on its way. We'll reply within a day.</p>Astro.site and BASE_URL come from site and base in astro.config.mjs, so set them. On GitHub Pages a project site (anything but yourname.github.io itself) is served from a subpath, and base has to match it:
// astro.config.mjs
import { defineConfig } from 'astro/config'
export default defineConfig({
site: 'https://yourname.github.io',
base: '/your-repo-name',
})With that config the built field is value="https://yourname.github.io/your-repo-name/thanks/". On your own domain, set site to it and leave base out. The URL has to be on the same site as the form. Anything else is ignored, and the visitor sees BootForm's own page.
Sending without leaving the page
To submit in the background and show a message in place, add a <script> to the component. Astro bundles it for you and treats it as TypeScript, so this is the script from the Vanilla JS guide's AJAX section with the types Astro expects. Give the form an id, add a paragraph for the message, and leave _redirect out, because it only applies to a classic form post:
<form id="contact-form" action={`https://f.bootform.com/${BOOTFORM_FORM_ID}`} method="POST">
<!-- the same fields as before, without the _redirect field -->
</form>
<p id="contact-status" role="status"></p>
<script>
const form = document.querySelector<HTMLFormElement>('#contact-form')!
const button = form.querySelector<HTMLButtonElement>('button[type="submit"]')!
const status = document.querySelector<HTMLElement>('#contact-status')!
form.addEventListener('submit', async (event) => {
event.preventDefault()
button.disabled = true
status.textContent = 'Sending...'
try {
const response = await fetch(form.action, {
method: 'POST',
headers: { Accept: 'application/json' },
body: new FormData(form),
})
const result = await response.json()
if (result.ok) form.reset()
status.textContent = result.ok ? 'Thanks, your message was sent.' : result.error
} catch {
status.textContent = 'Could not send. Check your connection and try again.'
} finally {
button.disabled = false
}
})
</script>The script reads the address from the form's own action, so the ID still lives only in src/consts.ts. It finds the form by its id, so use the component once per page.
File uploads and the moderated feed
Both work on an Astro site exactly as in plain HTML: see Vanilla JS, file upload and Vanilla JS, moderated content feed. A file upload needs the form claimed first.
Common problems
The build stops with Invalid URL. site is not set in astro.config.mjs, so Astro.site is empty and the _redirect URL can't be built. Set site to your site's address.
After sending, the visitor lands on a 404. The _redirect URL is wrong. Open the built page's source and check the value of the _redirect field. The usual cause on a GitHub Pages project site is the subpath written into site instead of base: with site: 'https://yourname.github.io/your-repo-name' and no base, the field comes out as https://yourname.github.io/thanks/.
Your editor or astro check reports type errors in the script. You pasted the plain JavaScript version. Astro checks a component's <script> as TypeScript. The site still builds and the script still runs, but the version on this page has the types and passes the check.
You sent a test message but no email arrived. The form isn't claimed yet. Nothing is delivered until it is; claim it and the messages sent so far are delivered. Held messages are kept for 48 hours.