Have you ever filled out a lengthy form online, only to lose your progress when you accidentally closed the tab or refreshed the page? While Webflow doesn't offer native form auto-saving, you can easily implement this functionality by adding our pre-built script to your site — no coding knowledge required.
This step-by-step guide will show you how to add auto-save capabilities to your Webflow forms, from implementing the script to testing the complete setup.
You'll learn how to configure form fields, manage saved data, and verify everything works correctly. The entire process takes just a few minutes and requires only basic Webflow knowledge.
Auto-saving forms can transform your user experience and significantly impact your conversion rates. Before diving into the implementation, let's understand when and why you might want to use this functionality.
Consider these common scenarios where form auto-save can be valuable:
Webflow form auto-save works by storing form data in the user's browser local storage. This creates a reliable way to preserve form progress without requiring server-side storage or user accounts.
This auto-save functionality has many benefits, including:
Let's walk through the process of setting up form auto-save on your Webflow forms.
First, add this custom script to your Webflow site:
<script>
/**
* BRIX Templates Auto-Save for Webflow Forms
* Automatically saves user input in localStorage in real time
* @version 1.0.0
*/
(function() {
'use strict';
// Configuration
const CONFIG = {
expiryDays: 7, // Number of days before saved data expires
saveInterval: 1000 // Save frequency in milliseconds
};
function initBrixAutoSaveForms() {
// Find all forms with our special attribute
const autoSaveForms = document.querySelectorAll('form[brix-templates-autosave]');
if (!autoSaveForms.length) {
console.log('No forms found with the attribute [brix-templates-autosave].');
return;
}
autoSaveForms.forEach((form, index) => {
// Create unique storage key for each form
const storageKey = `brixTemplatesAutoSaveForm_${index}`;
// Restore any saved data immediately
restoreFormData(form, storageKey);
// Save data periodically
setInterval(() => {
saveFormData(form, storageKey);
}, CONFIG.saveInterval);
});
}
function saveFormData(form, storageKey) {
// Get all form fields
const fields = form.querySelectorAll('input, textarea, select');
const formData = {
timestamp: new Date().getTime(), // Add timestamp for expiry checking
data: {}
};
fields.forEach(field => {
const key = field.name || field.id;
if (key) {
formData.data[key] = field.value;
}
});
// Save to local storage
localStorage.setItem(storageKey, JSON.stringify(formData));
console.log('Form data saved successfully');
}
function restoreFormData(form, storageKey) {
const savedData = localStorage.getItem(storageKey);
if (!savedData) return;
try {
const parsedData = JSON.parse(savedData);
// Check if data has expired
const now = new Date().getTime();
const expiryTime = parsedData.timestamp + (CONFIG.expiryDays * 24 * 60 * 60 * 1000);
if (now > expiryTime) {
localStorage.removeItem(storageKey);
return;
}
const fields = form.querySelectorAll('input, textarea, select');
fields.forEach(field => {
const key = field.name || field.id;
if (key && parsedData.data[key] !== undefined) {
field.value = parsedData.data[key];
}
});
console.log('Form data restored successfully');
} catch (error) {
console.error('Error parsing saved form data:', error);
}
}
// Initialize when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initBrixAutoSaveForms);
} else {
initBrixAutoSaveForms();
}
})();
</script>
Let's understand how this code works and how it enables this auto-save feature.
1. Form detection: Automatically finds forms with the brix-templates-autosave attribute.
2. Form data save process: Monitors form fields and saves data every second, storing the information with timestamps in the user browser local storage.
3. Form data restore and cleanup: Checks for and loads previously saved data when the page loads. If the data is older than 7 days (or any other time you prefer — more info below), it removes it automatically.
The auto-save script includes built-in data expiration after 7 days by default. You can adjust this by changing the expiryDays value in the CONFIG variable at the top of the script. For example, to make data expire after 30 days, set expiryDays: 30.
Choose where to implement the functionality based on your needs:
Page-specific implementation: Perfect when you only need auto-save on specific pages. To implement:
Site-wide implementation: Ideal when you want auto-save across multiple forms that are live on many (or all) pages on your website. To implement:
If you want to prevent a form from displaying previously submitted data when a user returns to it (i.e., after reaching the thank you page), add this simple cleanup script:
<script>
/**
* BRIX Templates Form Data Cleanup
* Clears all saved form data from localStorage
*/
(function() {
Object.keys(localStorage).forEach(key => {
if (key.startsWith('brixTemplatesAutoSaveForm_')) {
localStorage.removeItem(key);
}
});
})();
</script>
This script automatically cleans up all auto-saved form data from the browser's local storage. To add it, simply complete the following steps:
1. Open your Thank You page in Webflow Designer
2. Click the settings gear icon
3. Scroll to the "Before </body> tag" section
4. Paste the cleanup code
You can add this code to any page where you want to clear saved form data using the same steps.
This step is crucial for the auto-save functionality to work properly. Each field needs a unique identifier so the script can correctly save and restore the data:
Without these unique identifiers, the script won't be able to match saved data with the correct form fields when restoring content. Think of these labels as addresses—they tell the script exactly where to store and retrieve each piece of information.
Before going live, we recommend you to publish on your staging (webflow.io) domain and test the implementation:
You now have the knowledge to implement form auto-save functionality in your Webflow site. This feature can significantly improve user experience and form completion rates by ensuring no progress is lost.
While this implementation works perfectly for basic auto-save needs, there are more advanced scenarios you might encounter:
For these advanced implementations or custom solutions tailored to your specific needs, feel free to reach out to our dream team at BRIX Templates — we can help create a solution that perfectly matches your requirements.
Discover how to save time by automating lead transfers from Webflow to Klaviyo.
Learn how to automatically truncate long text in Webflow by adding a single custom attribute. 5-minute setup, no coding experience needed
Step-by-step guide to bypass Webflow's 3-field checkout limit. Learn how to add unlimited custom fields to your Webflow Ecommerce checkout.