How can I hide the Webflow form and display the page content once the form is submitted?

Published on
September 22, 2023

To hide the Webflow form and display the page content once the form is submitted, you can use a combination of Webflow's built-in form submission actions and custom code. Here's a step-by-step guide on how to achieve this:

  1. Add a form element to your page in Webflow. Customize the form fields according to your needs.

  2. In the form settings panel on the right sidebar, you can choose how the form submission should be handled. You have three options:

  • Redirect to Page: This option allows you to send users to a specified thank-you page after submitting the form. You can create a separate thank-you page in Webflow and set it as the redirect destination.
  • Show Message: This option displays a custom success message on the same page after the form submission.
  • Show Nothing: This option leaves the page as is without any visible confirmation.
  1. If you choose the "Show Nothing" option, you'll need to write custom code to hide the form and display the page content once the form is submitted. Here's an example of how you can achieve this using JavaScript:
<script>  document.addEventListener('DOMContentLoaded', function() {    var form = document.querySelector('#your-form-id'); // Replace with your form ID    var content = document.querySelector('#your-content-id'); // Replace with your content block ID    form.addEventListener('submit', function(event) {      event.preventDefault(); // Prevent form submission      // Hide the form and display the content      form.style.display = 'none';      content.style.display = 'block';    });  });</script>
  1. Replace 'your-form-id' with the actual ID of your form element and 'your-content-id' with the ID of the content block you want to display after form submission. You can find these IDs by inspecting the HTML code in your browser.

  2. Once you've added the custom code, publish your site to see the changes in action. When the user submits the form, the form element will be hidden, and the content block will be displayed.

By following these steps, you can effectively hide the Webflow form and display the page content once the form is submitted. This ensures a seamless user experience and allows your visitors to focus on the content of your page after submitting the form.

Additional Questions:

  1. How can I customize the success message after a form submission in Webflow?
  2. Can I send form submission data to an external database in Webflow?
  3. What are some best practices for designing a user-friendly form in Webflow?