Effortlessly Send Contact Forms with Web3Forms 📬

Web3Forms is a solution for those who want to create a functional contact form without the need for a backend. In this article, we’ll explore how to use Web3Forms and make your life easier. 🚀

Effortlessly Send Contact Forms with Web3Forms 📬
M
Muhammad Surya J

Overview 🌟

Web3Forms is a game-changer for developers who want to create fully functional contact forms without the hassle of setting up a backend server. This tool simplifies the process of collecting user data, making it perfect for static websites or projects where you want to avoid backend complexity. In this article, we’ll walk through integrating Web3Forms into your project, ensuring you can collect user data effortlessly. ✨

Getting Started 🛠️

Before diving in, you’ll need to generate an Access Key—a unique identifier that connects your form to Web3Forms. To get your Access Key, visit Web3Forms, sign up, and the key will be sent directly to your email. Keep this key handy, as it will be essential for configuring your form. 🔑

Creating The Template 🎨

To ensure our form looks polished, we’ll use Bootstrap for styling. Below is a basic HTML template that includes Bootstrap’s CSS framework:

<!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>
		<!-- Bootstrap CSS -->
		<link
			href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"
			rel="stylesheet"
			integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
			crossorigin="anonymous"
		/>
	</head>
	<body>
		<!-- Form Content Goes Here -->
	</body>
</html>

This template uses Bootstrap via a CDN, so ensure you have an active internet connection to load the styles correctly. If you already have a custom form, feel free to skip ahead. 🚀

Building The Form 🖥️

In this section, we’ll create a simple contact form with three fields: Email, Name, and Message. If you prefer different fields, you can customize the form to suit your needs. Here’s the code for the form:

<div style="height: 100vh; display: flex; align-items: center; justify-content: center">
	<div class="container">
		<div class="row justify-content-center align-items-center">
			<div class="col-lg-5 col-md-12 col-12">
				<div class="card">
					<div class="card-body">
						<form action="https://api.web3forms.com/submit" method="POST">
							<div class="mb-3">
								<label for="email" class="form-label">Email</label>
								<input type="email" class="form-control" id="email" name="email" required />
								<input type="hidden" name="access_key" value="YOUR_ACCESS_KEY_HERE" />
							</div>
							<div class="mb-3">
								<label for="name" class="form-label">Name</label>
								<input type="text" class="form-control" id="name" name="name" required />
							</div>
							<div class="mb-3">
								<label for="message" class="form-label">Message</label>
								<textarea
									class="form-control"
									id="message"
									rows="3"
									name="message"
									required
								></textarea>
							</div>
							<button type="submit" class="btn btn-primary">Submit</button>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

Key Attributes Explained 🔧

AttributeDescription
value="YOUR_ACCESS_KEY_HERE"Replace YOUR_ACCESS_KEY_HERE with the Access Key you received via email.
nameEach input field must have a name attribute to ensure data is captured correctly.

Finally, add the following script just before the closing </body> tag to enable Web3Forms functionality:

<!-- Web3Forms Script -->
<script src="https://web3forms.com/client/script.js" async defer></script>

<!-- Closing Body Tag -->
</body>

Submitting The Form ✅

Once your form is set up, test it by filling out the fields and clicking Submit. If everything is configured correctly, you’ll be redirected to a success page provided by Web3Forms. Additionally, you should receive an email containing the submitted form data. 📧

Conclusion 🎯

Web3Forms is an excellent solution for developers who want to avoid the complexities of backend development. While this article covers the basics, Web3Forms offers a variety of advanced features, such as:

  • Customizing the email subject. ✏️
  • Redirecting users to your own success page. 🌐
  • Adding Google reCAPTCHA for spam protection. 🔒
  • Allowing file uploads. 📂

By leveraging these features, you can create robust and user-friendly contact forms tailored to your specific needs. Happy coding, and may your forms work flawlessly! 💻✨