I have an action, /controller/edit, which can be clicked to from multiple locations (e.g. /controller/index and /controller/view).
Once the user has finished editing the record and clicks save, I want them to return to wherever they came from (/controller/index or /controller/view respectively).
At first I tried storing each page the user visits in their session (e.g. home > index > edit), and then redirecting to the second-to-last entry in that list - and that works fine right up until they open another tab. If, while they're editing the record they open another tab and go off somewhere else, their session variable keeps being built on (home > index > edit > help > help page), and when the time comes to redirect the second-to-last entry no longer contains the correct action.
How can my edit action /controller/edit, on save, redirect the user back to the referring page they came from to get there, independent of whatever the user has done in other tabs?
Edit: I can't use referrer after save because the process is this:
- User is on either /controller/index or /controller/view
- User clicks into /controller/edit (referrer is /controller/index or /controller/view)
- User makes changes to record and clicks save, which form submits to /controller/edit (referrer is /controller/edit)
- I now want to redirect them to either /controller/index or /controller/view, but that is no longer in the referrer