How to Create a Custom Success Message in Webflow Form Submission | Webflow Tutorial

Published on
May 13, 2019

How to Create a Custom Success Message in Webflow Form Submission

Are you looking for a way to provide a more personalized experience for your website visitors? Along with the native features of Webflow, you can create a custom success message that dynamically updates based on the information entered into the form. In this tutorial, we will guide you through the process of implementing a custom success message after a Webflow form submission. Let's dive into the details and learn how to achieve this using Webflow.

Setting Up the Form in Webflow Designer

Firstly, to get started with this customization, you need to have a Webflow form set up in your project. Within Webflow Designer, locate the form element you want to work with. Apply some specific IDs and classes to the form elements to make them targetable for your custom success message.

  1. Form Wrapper ID: Apply an ID of "email-form" to the form wrapper.

  2. Select Field ID: Apply an ID of "interest-select" to the select field. This ID will be used to pull information from the form to generate the success message.

  3. Success Text Class: Apply a class of "insert-success-text" to the success text wrapper. This class will allow you to change the text dynamically using JavaScript.

By giving these form elements unique identifiers, you can easily target them with JavaScript to create the customized success message.

Implementing the Custom Success Message Script

Now, let's move on to writing the JavaScript code to dynamically update the success message based on the user's input. Below is the step-by-step breakdown of the code that needs to be inserted before the closing </body> tag of your Webflow project.

<script>  // Store a reference to the Select field in the interestSelect variable  var interestSelect = document.getElementById('interest-select');  // Store a reference to the email form and store it as the emailForm variable  var emailForm = document.getElementById('email-form');  // Store a reference to the insert success text class and store it as a successText variable  var successText = document.querySelector('.insert-success-text');  // Declare and initialize a custom success message variable  var customSuccessMessage;  // Update the custom success message variable whenever the select field value changes  interestSelect.addEventListener('change', function() {    customSuccessMessage = "Thank you. We'll focus on " + interestSelect.value;  });  // Handle form submissions  emailForm.addEventListener('submit', function(event) {    if (interestSelect.value) {      successText.innerText = customSuccessMessage;      // You can optionally perform additional actions here before form submission    } else {      event.preventDefault(); // Stop the form submission      alert('Please select an option in the interest field.'); // Provide a prompt to select an option      // You may choose to show the error message next to the select field    }  });</script>

Let's break down the functionality of the JavaScript code:

  • We start by storing references to the select field, the email form, and the success text element.

  • A custom success message variable is declared and initialized with an initial value.

  • We listen for changes in the select field's value and update the custom success message accordingly.

  • When the form is submitted, we check if an option has been selected in the select field. If so, we update the success text with the custom message. If no option is selected, we prevent the form submission and prompt the user to select an option.

Applying the Custom Success Message in Webflow

After inserting the JavaScript code into your Webflow project, you are now able to provide a personalized success message to your form submissions. The success message will dynamically update based on the option selected by the user.

By following these steps, you can create a more engaging and interactive form submission experience for your website visitors. This level of customization adds a personal touch to your website and enhances user engagement.

Conclusion

In this tutorial, we've learned how to show a custom success message after a Webflow form submission using JavaScript. With the power of Webflow's native form elements and JavaScript, you can provide a personalized and interactive user experience on your website.

Start experimenting with this customization in your Webflow projects and see how it enhances the user experience. Stay tuned for more Webflow tutorials and tips to level up your design and development skills. If you want to explore more hacks and stay updated with the latest releases, make sure to subscribe to our YouTube channel and sign up for email updates at Finsweet.

Don't hesitate to clone the project and start implementing these hacks on your live site. Have fun customizing your Webflow forms and providing a seamless user experience for your website visitors!