This technique demonstrates how to capture form data in real-time using localStorage
, then retrieve and display it dynamically on a redirected page such as a thank-you or confirmation screen.
The approach works by listening to user input events on the form page, saving each input's name and value to localStorage
as the user types. Once the form is submitted and the user is redirected, custom code on the destination page retrieves this saved data and displays it in designated page elements. For the retrieval to work reliably, the input names and the IDs of the destination page elements must align precisely.
This client-side pattern is lightweight, requires no backend setup, and can be a valuable enhancement for form-driven Webflow projects.
Example of code that can be used to save user input selection to local storage and retrieve it on the relevant page.
Main page where the form is.
// Get the form element by its ID
const form = document.getElementById("form");
// Add an event listener to the form for any input event
form.addEventListener("input", function (event) {
// Try to get the existing form data from localStorage, or use an empty object if none exists
let formData = JSON.parse(localStorage.getItem("formData")) || {};
// Update the formData object with the new value from the input that triggered the event
formData[event.target.name] = event.target.value;
// Save the updated formData object back to localStorage as a JSON string
localStorage.setItem("formData", JSON.stringify(formData));
});
Page user is redirected to i.e., /thank-you page.
// Retrieve saved form data from localStorage
const formData = JSON.parse(localStorage.getItem("formData"));
if (formData) {
// Iterate over each key in the formData object
Object.keys(formData).forEach(function (key) {
// Find the element with the corresponding id
const el = document.getElementById(key);
if (el) {
// Set the element's text content to the saved value
el.textContent = formData[key];
}
});
}
Inspect and clone this project to investigate/test as needed: https://webflow.com/made-in-webflow/website/form-saved-values.
name
attribute on the form page must match the id
of the element where the value will be displayed on the thank-you page.name="firstName"
and id="firstname"
will silently fail.localStorage
has a limit (~5–10MB depending on the browser), which is more than enough for simple forms, but not ideal for large uploads or file inputs.localStorage
access to work.input
event, data is saved as the user types. This helps with session recovery if the page reloads or crashes.event.target.value
reflects the correct state—especially for unchecked or default options.localStorage
is persistent across sessions. If you don’t manually clear it, saved form data might be visible to the next visitor.sessionStorage
if you want the data to disappear once the tab or browser is closed.