Written by: Geoffrey Callaghan
How To Create A Contact Form With Vercel
How To Create A Contact Form With Vercel
Creating a contact form on Vercel involves a few key steps. Here’s a simplified guide using HTML, JavaScript, and a third-party service like FabForm.io for handling form submissions:
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Form</title>
</head>
<body>
<form id="contactForm" action={process.env.FABFORM_ENDPOINT} method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="message">Message:</label>
<textarea id="message" name="message" required></textarea>
<button type="submit">Submit</button>
</form>
</body>
</html>
FABFORM_ENDPOINT
and set its value to the form endpoint URL provided by FabForm.io.<!-- Add this script at the end of the body or in a separate JavaScript file -->
<script>
const contactForm = document.getElementById('contactForm');
contactForm.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(contactForm);
const response = await fetch(process.env.FABFORM_ENDPOINT, {
method: 'POST',
body: formData,
});
if (response.ok) {
alert('Form submitted successfully!');
contactForm.reset();
} else {
alert('Error submitting the form. Please try again later.');
}
});
</script>
Now, your contact form should be live on your Vercel site, and submissions will be sent to FabForm.io for processing. Users will receive a confirmation, and you can manage submissions through the FabForm.io dashboard.