0

I've created a search page using Views with exposed filters and the basic search module. The search only returns results for a specific node content type 'resource'. A typical use case would be the following:

User goes to search page, types some text into the exposed search terms block, and also selects some options from the exposed filters that are drop-down menus. They click 'search' and their results are returned on the same page. Pretty standard stuff and I have that all working fine.

A user then clicks a link to a resource node of interest to them and goes to that node's profile page. All fine and dandy.

The problem is when they want to go BACK. I went ahead and added a back button with the following code to my node--resource.tpl.php, which works as you'd expect (it bypasses the browser back button and takes user to main search page again):

<input type="button" value="Go Back" onclick="window.history.back()" />

What happens is it displays the search page again, but no longer with the search term they entered OR the exposed filters they selected. I'd like to change that so when they click the 'back' button the search page still shows their search results from before so they don't have to re-select all their options again.

This seems like pretty basic stuff, but I can't figure out how to do it in Drupal. I imagine it involves session cookies somehow...but how to combine this with Views I do not know.

Thanks for your help!

  • Could add. target="_blank" to the links to force a new window – Geoff Jun 1 '15 at 20:22
  • @Geoff thanks but that is not ideal to my situation, although it works as a temporary fix I suppose. – Sage Jun 1 '15 at 22:00
  • @Geoff see my totally revised question above. Thanks. – Sage Jun 1 '15 at 22:33
0

Ok, I solved my own question. To get Views search results to 'stick' you just have to select an option for each filter you want to save and the role that this works for.

In Views > Filters > check the box next to 'remember the last selection' and select which roles this applies to.

Easy. Now when a user clicks the 'back' button I've added to the tpl file it takes them back to their selections.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.