Forum Moderators: coopster

Message Too Old, No Replies

Passing existing $_POST to next page

allow a results page to 'post' to itself the received $_POST vars

         

SteveT

7:36 am on Jun 21, 2004 (gmt 0)

10+ Year Member



Hi guys, first post - been using webmasterworld for a while and found it very handy.

Heres my question, it applies to the problem below (answer the general question and I can abstract it to work for my needs).

Can I create an associative array and have it sent to the next page via the $_POST array? If not,
how do I pass an associative array to a .php page? It would be best to avoid having to deliminate and implode/explode it.

2nd question: Is the only way to 'post' data to a php page to use a form? eg. I could simulate a GET form by just using an url with appended GET key/value pairs - any way to simulate a POST?

Thanks

Actual problem:

My results.php file recieves $_POST variables from the search.php file. Now I only display 10 results on the results.php page at once, so I want to be able to pass on all these existing POST var's including modification (eg. $_POST['page_no'] = $_POST['page_no']+1 for 'next', or changing a whole bunch of them if an entire 'refine search' form is filled in) to the results.php file when certain links are clicked ('next', 'previous', 'order by').

I want to avoid having a form for each results.php link that must use a lot of hidden fields to pass on all the existing values in $_POST.

Request an examples of code if you need clarification.

Oh, and it would be good if there's a non-session(/non-cookie) way of doing it.

carneddau

8:51 am on Jun 21, 2004 (gmt 0)

10+ Year Member



Hi SteveT,

Have you looked at the serialise function?

From the manual:
"serialize() returns a string containing a byte-stream representation of value that can be stored anywhere.

This is useful for storing or passing PHP values around without losing their type and structure."

Could be what you're looking for.

Russ49Checkmate

1:55 pm on Jun 21, 2004 (gmt 0)

10+ Year Member



I have a series of scripts that all need data from the very first HTML form, < ... name=\"unit\" value=\"16\" ...>

So I just insert into the later scripted forms:
<input type=hidden name=\"unit\" value=\"$_POST[unit]\">
and thus I have the data for each script.

jatar_k

5:52 pm on Jun 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld SteveT,

the only choices you really have are

$_GET // might be what you are looking for
$_POST // will require the data to be written into the form
$_SESSION // you said no
$_COOKIE // you said no

any of them will work

serialize/unserialize will work to have a single value with any of these (GET you would have to test I think). I think I would use GET or SESSION the more complex the data the more I see SESSION being the most intuitive.

Just do a big GET string like the search engines do.

SteveT

12:44 am on Jun 22, 2004 (gmt 0)

10+ Year Member



Thanks carneddau, Russ and jatar.

Decided to go for GET, and start practicing with SESSION :)