How to maintain search criteria among pages

Hi all,

I am going through a dilema and I would like to ask you for a possible solution to this scenario:

  1. User makes a search through a form.

  2. Parameters are received and a CDbCriteria is built

  3. Results displayed

  4. When user clicks a result, new page viewing the selected record is displayed

My question is:

What is the best option to put a link heading back to results page? -location.back is not good as form is POSTED and I dislike the fact to force user to refresh POSTED values (browser requires to do so).


What is the best way to save criteria? Maybe is because I am tired but I cannot decide for the best solution:

a ) Save last search params in a session cookie and check if user POSTs or returns -checking REFERER.

b ) Save last search params in encoded string and attached it to each result link (encoded string will construct the ‘back to results’ link

I have used the second option. I encode, decode and attach to the Link of the displayed page to go back. If anybody requires help with this, let me know.

If its just a search form is it not best just to use GET instead of POST?

Hi GSTAR,

Thanks for replying.

I used POST cuz I truly do not like long params attached to the URL and even less those who show param names.

The solution that I use, checks against a getParam parameter (cci), if exists, then I can rebuild the search back again.

try this extension

http://www.yiiframework.com/extension/xreturnable/

Thank you Flavio… did it already but I keep this extension for the future!

The problem was that I had POST and GET variables to deal with. I have seen the code within the extension and is quite good. I may look at its guts with a bit more time in order to change its handling for both param var types.

Thanks again!

Great Extension, thanks for pointing me Flavio… My vote for you!

Despite Even though, i’ve written that extension, i’m not sure anymore wether it’s really that useful. :)

Frankly speaking, i’ve never used it anywhere myself. The only place where it could be practical might be in some backend application. For frontends i’d use your approach b ), because it follows KISS and always creates URLs that are human readable.

EDIT: english can be hard sometimes ;)

How about creating a stateful form? Have a read of this:

http://www.yiiframework.com/forum/index.php?/topic/7774-stateful-forms

Thank you Mike. Nevertheless, I think your extension is great. I have checked out the code and I think that with some tweaks I can actually do what I did for my code. It just needs to support POST.

Thank you for your support Mike.

Thank you GSTAR… I will check it out… Once I publish the site, you will see what i meant.

Best

Hmm, i can’t imagine how this should work - but i guess you know what you’re doing. ;)

Also check out the forum topic on the extension. Maybe it helps to even better understand the rationale behind it.

Hi Mike,

I have read through all the extension :)

The dilema I was facing was that I had to return to a page that was previously results presented by a POST (forward) or GET (return) values…

As I see your extension collects GET values… I let you know when I have time…

BTW Mike… 2000 posts… congrats

OMG, maybe I should get a life