Skip to content

About

Vanilla JavaScript contact form using fetch() and the Formclick form API. No framework, no build step, no backend.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript contact form

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.

Quick start

  1. Create a free account at formclick.io, create a form and copy its access key.
  2. Clone the repo:
    git clone https://github.com/formclick/javascript-contact-form.git
    cd javascript-contact-form
  3. In script.js, set ACCESS_KEY to your key.
  4. 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.

How it works

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").

Prefer no JavaScript of your own?

Add formclick.min.js and point the form's action at Formclick; the script handles submitting and messages for you. See html-form-examples.

Responses

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.

Learn more

License

MIT

About

Vanilla JavaScript contact form using fetch() and the Formclick form API. No framework, no build step, no backend.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages