Written by: Geoffrey Callaghan

How To Create A Contact Form In Webflow

How To Create A Contact Form In Webflow

Creating a contact form in Webflow with FabForm.io involves the following steps:

Step 1: Set Up Your FabForm.io Account

  1. Visit FabForm.io and sign up for an account if you don’t have one.

  2. Create a new form and note the form endpoint URL provided by FabForm.io. It usually looks like https://fabform.io/f/YOUR_FORM_ID.

Step 2: Design Your Form in Webflow

  1. Open your Webflow project and navigate to the page where you want to add the contact form.

  2. Drag and drop form elements onto your page. Common form elements include text fields for the name and email, a textarea for the message, and a submit button.

  3. For each form field, click on it, go to the Settings panel, and set the “Name” attribute. Make sure the attribute names match the field names in FabForm.io.

Step 3: Add Custom Code to Your Webflow Project

  1. Select the Page Settings in Webflow.

  2. Go to the “Custom Code” section.

  3. Add the following code inside the “Head” tag of your HTML:

    <script>
      document.addEventListener('DOMContentLoaded', function () {
        const form = document.getElementById('your-form-id'); // Replace with your actual form ID
        form.addEventListener('submit', async function (event) {
          event.preventDefault();
    
          const formData = new FormData(form);
          const response = await fetch('https://fabform.io/f/YOUR_FORM_ID', {
            method: 'POST',
            body: formData,
          });
    
          if (response.ok) {
            alert('Form submitted successfully!');
            form.reset(); // Reset form fields after successful submission
          } else {
            alert('Form submission failed.');
          }
        });
      });
    </script>

    Make sure to replace 'https://fabform.io/f/YOUR_FORM_ID' with the actual URL generated by FabForm.io for your form. Also, replace 'your-form-id' with the actual ID of your form in Webflow.

Step 4: Publish Your Webflow Site

  1. Save your changes in Webflow.

  2. Publish your Webflow site.

  3. Test the contact form on your live website to ensure that it’s submitting data to FabForm.io correctly.

This setup allows you to use Webflow’s visual editor to design your form while integrating with FabForm.io for form handling. The custom code ensures that form submissions are sent to FabForm.io when users submit the form on your live website.