Written by: Geoffrey Callaghan
Create a Contact Form With jQuery
Create a Contact Form With jQuery
To create a contact form using fabform.io and jQuery, you’ll need to follow these steps:
Create an Account on Fabform.io:
Include jQuery in your HTML:
<head>
section of your HTML file.<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
Create the HTML Form:
action
attribute with the form endpoint URL provided by Fabform.<form id="contactForm" action="YOUR_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>
<input type="submit" value="Submit">
</form>
Replace "YOUR_FABFORM_ENDPOINT"
with the actual endpoint URL you obtained from Fabform.io.
Submit Form Data using jQuery:
<script>
$(document).ready(function () {
$("#contactForm").submit(function (e) {
e.preventDefault();
var formData = $(this).serialize();
$.ajax({
type: "POST",
url: "YOUR_FABFORM_ENDPOINT",
data: formData,
success: function () {
alert("Form submitted successfully!");
// You can redirect or perform other actions after successful submission
},
error: function () {
alert("Error submitting the form. Please try again later.");
}
});
});
});
</script>
Again, replace "YOUR_FABFORM_ENDPOINT"
with the actual endpoint URL you obtained from Fabform.io.
Test Your Form:
Make sure to replace placeholder text with your actual Fabform.io endpoint URL. This example assumes you have basic knowledge of HTML, jQuery, and working with APIs. Additionally, ensure that your website allows cross-origin requests to the Fabform.io domain.