Search code examples
phphtmlformszen-cart

serializing the POST array to be able to pass lots of data through a link


I'm having a noobie problem getting my head round how I can make this work.

I have a page listing products from my DB. On that page there is a filter form which POSTs lots of data to refine the product listing, ie how many results per-page, sort order, pricefrom, priceto plus an array of subcategories

I also have a paging system which is just the standard zencart (splitpageresults::dsplaylinks incase anyone is familiar) paging system which shows links for the next, previous and some page numbers. Normally it would pass params as $_GET at the end of the links but I have all these fancy filters I've made.

My idea is to serialize the $_POST array and send it as a $_GET param in the links:

<a href="index.php&arr=<?php echo serialize($_POST[]);?>">nxt</a>

but is this seems bad all the serializing and unserializing.

What's the best way of doing this?

I can't figure it out!


Solution

  • You can remove the [] and urlencode() the serialized data:

    <a href="index.php&arr=<?php echo urlencode(serialize($_POST));?>">nxt</a>
    

    But you better use sessions. See the manual.