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:

  1. Create an Account on Fabform.io:

    • Go to Fabform.io and sign up for an account.
    • Create a new form, and note down the form endpoint URL provided by Fabform.
  2. Include jQuery in your HTML:

    • Add the jQuery library to your HTML file. You can include it by adding the following script tag in the <head> section of your HTML file.
    <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
  3. Create the HTML Form:

    • Create a simple HTML form with the necessary fields. Make sure to include the 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.

  4. Submit Form Data using jQuery:

    • Use jQuery to handle the form submission and send data to Fabform.io.
    <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.

  5. Test Your Form:

    • Save your HTML file and open it in a web browser. Test your form by filling in the details and submitting it.

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.