Browser back button to search results

2 posts by 2 authors in: Forums > CMS Builder
Last Post: April 7, 2014   (RSS)

By Chris - April 7, 2014

Hi Greg,

GET is a very simple solution. If you View Source in our forums, you can see that we're using method="GET" and a little trick with the submit button (type="button" onclick="this.form.submit();") so that it doesn't clutter up the URL with &submit=Search.

Another, more complex solution is to store the search criteria in a cookie (or several, or the session), then do a redirect to a regular GET page which reads from the cookie and performs the search (perhaps by injecting the criteria from the cookie into $_REQUEST). The page which resulted in the redirect gets skipped over when the user goes back in their browser. Note that you may need to account for accidentally remembering search criteria: when someone clicks to go to your list page, they're probably expecting to see all the results, not the filtered results from the last search they did. Getting this all working properly is non-trivial.

It's also possible to use Javascript to submit the form and replace the current page with the results returned, but then the search results page won't show up in the history at all, unless you manipulate the history with the HTML5 history API, but that's getting really, really complicated!

Hope this helps!

All the best,
Chris