A working contact form in plain HTML and vanilla JavaScript that sends submissions with the Formclick form API. No framework, no build step, no backend: one fetch() call, and every message lands in your inbox and your Formclick dashboard.
- Create a free account at formclick.io, create a form and copy its access key.
- Clone the repo:
git clone https://github.com/formclick/javascript-contact-form.git cd javascript-contact-form - In
script.js, setACCESS_KEYto your key. - Serve the folder (for example
npx serve .), open the page and send a test message.
Opening index.html straight from disk also works in most browsers; a local server avoids file:// restrictions on ES modules.
| File | Role |
|---|---|
index.html |
The form markup, plus a hidden thank-you card. |
script.js |
Submits the form with fetch() and shows the result. |
styles.css |
Layout and styling. Replace it with your own. |
form.addEventListener('submit', async (event) => {
event.preventDefault();
const data = Object.fromEntries(new FormData(form));
const res = await fetch('https://api.formclick.io/submit', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
body: JSON.stringify({ ...data, access_key: ACCESS_KEY }),
});
const result = await res.json(); // { success, message }
});| Piece | Why it's there |
|---|---|
event.preventDefault() |
Stops the browser's normal post, so the page doesn't reload. |
new FormData(form) |
Collects every input with a name. Add a field to the HTML and it's sent automatically. |
access_key |
Identifies your form. It can only create submissions, so it's safe in public code. |
_honeypot |
A hidden spam trap. Bots fill it and those submissions are silently discarded. |
res.status === 429 |
Formclick limits repeated submissions from one visitor; the page shows a friendly message. |
result.message |
On errors, Formclick returns a readable reason (for example "Form not found"). |
Add formclick.min.js and point the form's action at Formclick; the script handles submitting and messages for you. See html-form-examples.
| Status | Meaning |
|---|---|
200 |
Saved and delivered. |
400 |
Missing or invalid access key, empty submission, or a failed captcha. |
403 |
Form disabled, website not on the form's allowed domains, or monthly limit reached. |
404 |
No form exists for this access key. |
429 |
Too many submissions from one visitor in a short time. |