An Astro page can hold an ordinary HTML form that posts to FormKeep. It needs no adapter, endpoint or server rendering, so it works on a fully static site.
https://formkeep.com/f/YOUR-TOKEN.src/pages/contact.astro and paste the form, with your URL as the action.The simplest version is the form alone:
<form action="https://formkeep.com/f/YOUR-TOKEN" method="POST">
<input name="email" type="email" required />
<textarea name="message" required></textarea>
<button type="submit">Send</button>
</form>
To stay on the page and show your own message, add the script. Without JavaScript the form still posts normally. This is the whole page:
---
// src/pages/contact.astro
---
<form id="contact" action="https://formkeep.com/f/YOUR-TOKEN" method="POST">
<label>
Email
<input name="email" type="email" required />
</label>
<label>
Message
<textarea name="message" required></textarea>
</label>
<button type="submit">Send</button>
<p id="contact-status" role="status"></p>
</form>
<script>
const form = document.getElementById('contact') as HTMLFormElement;
const status = document.getElementById('contact-status') as HTMLElement;
form.addEventListener('submit', async (event) => {
event.preventDefault();
status.textContent = 'Sending...';
try {
const response = await fetch(form.action, {
method: 'POST',
headers: { Accept: 'application/json' },
body: new FormData(form),
});
if (!response.ok) throw new Error(`FormKeep answered ${response.status}`);
form.reset();
status.textContent = 'Thanks, we got your message.';
} catch (error) {
status.textContent = 'Something went wrong. Please try again.';
}
});
</script>
The request asks for JSON with Accept: application/json, so FormKeep does not redirect. A stored submission answers 200 with the body null; the page stays where it is and shows its own message. A wrong token answers 404 and a form switched off answers 403, and the code above shows the error message for both. The submission appears in your dashboard and your inbox.
Without the script, or if it fails to load, the browser is redirected to the redirect URL set in the form's Redirects tab, or to FormKeep's own thank-you page if none is set.
Add a file input and enctype="multipart/form-data" to the <form>. The script's FormData sends multipart on its own.
<form action="https://formkeep.com/f/YOUR-TOKEN" method="POST" enctype="multipart/form-data">
<input name="resume" type="file">
<button type="submit">Send</button>
</form>
Each file can be up to 10 MB and a submission can carry up to 50 files. Whether attachments are kept depends on your plan.
{"error":"This form is not accepting submissions."}. The form has been switched off. Switch it back on, or use another form.id in getElementById must match the form's id; a typo throws before the submit handler is attached and the browser posts the form normally.