0

I am trying to find out the best possible way to save the POST data in session and making it available in different page requests.

For example at website's homepage I have a Search form with different fields. On Submitting the form a product's page is displayed containing a list of all product matching the search criteria.

On selecting a product product's detail page is loaded. and on Detail page we have a back link to the Product's list page. on clicking the link, I am interested that the controller should load only the product depending on the search parameters. This means that maybe the search criteria will be saved in Session and on coming back to List or Search page these parameters will be loaded again from Session.

Is there any Best Practices or Design pattern available to to and load the Search Form fields?

user3733648
  • 109
  • 1

1 Answers1

1

Lets assume index.php as your home page.

I can assume that your controller might work using a action parameter appended to the URL or based on request parameter set.

index.php?search would takes the controller to execute search logic and there you get all post data of search criteria. and loads products based on a query mapped with data keywords entered by user.

There you show each product mapping the criteria.

and for details, you might be using, index.php?productDetail=product_id (or) some thing.

Here you can simple modification by adding all the search fields data to

index.php?productDetails=product_id&search1=val1&search2=val2&...

Then append all these get parameters to the Back Link of Product details page, this way you can get all search data to the product list page back.

Importantly make small changes in your controller to search based on Get parameters as well, i.e., like if you are using $_POST to read search form data change it to $_GET, so that the same search result page will be loaded even if the user clicked back from the product detail page.