Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Back button loses form or cart state: how to find and fix it

PRF-230Medium impactCould addBy FunnelGuardPublished Updated
On this page

What this issue is

A visitor fills in part of a form or adds items to a cart, clicks a link (a terms page, a shipping policy, a payment step), then presses the browser's Back button. They expect to land where they were, with everything still there. Instead the form is blank, a multi-step form restarts, or the cart shows zero items.

Why it costs you leads or sales

Re-typing is work. Many visitors will not do it twice. On mobile, where typing is slow, the loss is worse. A lost cart is worse still: the visitor has to find the products again, and some will buy elsewhere instead.

Visitors who finish after pressing BackExample numbers
Visitors who finish after pressing Back (example)State kept: 70 %; State lost: 35 %027547035State keptState lost%

Example: illustrative numbers only. Of 100 visitors who press Back mid-form, fewer finish when their entries are gone.

Where the journey breaks
  1. Fill in form / add to cartVisitor invests effort
  2. Open another pageTerms, shipping info, payment step
  3. Press BackFields empty, cart reset
  4. Re-enter detailsMany give up here
  5. Lead or orderNever completed

The break happens on return, so everything after it is lost.

How to check if your site has it

This takes five minutes and needs no tools. Test on desktop and on a real phone, because mobile browsers handle the cache differently.

Manual back-button test
  1. Fill in the form

    Type into several fields, including a dropdown, a checkbox and a text area. Do not submit.

  2. Leave the page

    Click an internal link such as the privacy policy, then press Back.

  3. Check the fields

    Note which values survived. Repeat in Chrome, Safari and Firefox.

  4. Test the cart

    Add a product, open another page, press Back, then check the cart count and contents. Also try going back from the checkout step to the cart.

  5. Test multi-step forms

    Go to step 3, press Back once. You should land on step 2 with its answers, not on step 1 or a blank page.

  6. Inspect headers

    In Chrome DevTools, open Network, click the page request and read the Response Headers. Look for Cache-Control: no-store.

How to fix it

Start with the cause the test pointed to. The usual ones are below.

Common causes and fixes
CauseSymptomFix
Cache-Control: no-store on the pagePage reloads fresh, fields emptyUse no-cache or private, max-age=0 on form pages where safe
unload or beforeunload handlerPage not eligible for bfcacheReplace with pagehide or visibilitychange
autocomplete="off" on fieldsBrowser will not restore typed valuesRemove it, except on sensitive fields such as card numbers
Form built by JavaScript after loadFields render blank on returnSave values to sessionStorage and refill them
Script calls form.reset() on loadValues wipedOnly reset after a successful submit
Cart stored only in page memoryCart empty after BackStore the cart in a cookie, server session or localStorage
Fix by platform
  1. Check caching and security plugins

    Some plugins send no-store headers on pages with forms. Look in your cache, security and membership plugin settings for options about sending no-cache headers, and exclude form pages from them where possible.

  2. Review your form plugin

    Look in the form plugin's settings for options about saving partial entries or progress on multi-step forms. Availability depends on the plugin and version.

  3. Test with plugins off

    On a staging copy, deactivate plugins one at a time and repeat the Back test to find the culprit.

Save and restore form values (skip sensitive fields)javascript
const form = document.querySelector('#lead-form');
const KEY = 'lead-form-draft';

function save() {
  const data = {};
  new FormData(form).forEach((v, k) => {
    if (k !== 'card_number' && k !== 'password') data[k] = v;
  });
  sessionStorage.setItem(KEY, JSON.stringify(data));
}

function restore() {
  const saved = JSON.parse(sessionStorage.getItem(KEY) || '{}');
  Object.entries(saved).forEach(([name, value]) => {
    const el = form.elements[name];
    if (el && !el.value) el.value = value;
  });
}

form.addEventListener('input', save);
window.addEventListener('pageshow', restore);
form.addEventListener('submit', () => sessionStorage.removeItem(KEY));
Replace unload with pagehidejavascript
// Before: blocks the back/forward cache
window.addEventListener('unload', sendData);

// After
window.addEventListener('pagehide', sendData);
Allow back/forward cache on a form pagenginx
location /contact/ {
    add_header Cache-Control "private, max-age=0, must-revalidate";
}
Pressing Back

Before

  • Form fields are empty
  • Multi-step form restarts at step 1
  • Cart shows 0 items

After

  • Typed values are still there
  • Visitor returns to the step they left
  • Cart keeps its items

How to confirm it's fixed

Confirmation checks
  • Repeat the manual test in Chrome, Safari and Firefox on desktop
  • Repeat it on a real iPhone and an Android phone
  • Run Chrome's Back/forward cache test and confirm the page is restorable
  • Check the cart count and contents after Back
  • Check that a successful submit still clears the saved draft
  • Submit a test lead to confirm the form still works and arrives

How to prevent it happening again

Prevention habits
  • Add the Back test to your release checklist for any form, cart or checkout change
  • Review new plugins, apps and tags for unload handlers and no-store headers
  • Avoid autocomplete="off" except on sensitive fields
  • Keep carts server-side or in persistent storage
  • Retest after theme updates and caching or CDN changes

How FunnelGuard handles this

FunnelGuard does not check for this yet. Testing Back-button behaviour is a possible future check, so for now you need to test it by hand or with browser tools as described above.

What FunnelGuard does cover nearby: a robot visitor runs your real journeys on a schedule, such as lead forms and checkouts, and checks each step, the tracking hits and whether test leads reach your inbox and CRM. If a change breaks the form or checkout itself, that is the kind of failure it re-checks from a second region before sending one alert with a screenshot and likely cause. That will not tell you whether Back restores entries.

Questions people ask

Why does my form clear when I press the back button?

Usually the browser cannot restore the page from cache. Typical causes are a Cache-Control: no-store header, an unload handler, autocomplete="off" on the fields, or a script that resets the form on load. Test in Chrome DevTools under Application, Back/forward cache to see the exact reason.

Why is my cart empty after I click back?

The cart may be held only in page memory or fetched in a way that is not repeated when the page is restored. Store the cart in a server session, cookie or persistent storage, and reload it from there on page load.

How do I stop the back button from losing form data?

Remove no-store headers and unload handlers from the form page, drop autocomplete="off" from non-sensitive fields, and save progress to sessionStorage so you can refill fields when the page is shown again. Clear the saved draft after a successful submit.

What is the back/forward cache (bfcache)?

It is a browser feature that keeps a snapshot of a page in memory when you leave it. Pressing Back then shows the page instantly, with form values and scroll position intact. Some code, such as unload handlers, stops a page being stored.

Is it safe to save form data in the browser?

It is fine for ordinary fields like name or message when you use sessionStorage, which clears when the tab closes. Never store card numbers, passwords or other sensitive data, and delete the draft after submission.

Does the back button problem affect multi-step forms?

Yes, and often more. If each step is loaded by JavaScript without updating history, Back can leave the form entirely or restart it. Give each step its own history entry and keep earlier answers stored so Back returns to the previous step with its answers.

Can FunnelGuard detect when the back button loses form state?

No, not yet. It is a possible future check. FunnelGuard does run your real journeys on a schedule and checks that steps, tracking and test leads work, but you need to test Back behaviour manually for now.

Does FunnelGuard catch this?

Could add

Not checked yet: could be added to FunnelGuard.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.