Forum Moderators: coopster

Message Too Old, No Replies

Passing $_POST between more than one script

Passing $_POST between more than one script

         

kamkaz

10:19 am on Mar 6, 2005 (gmt 0)

10+ Year Member



Hello,
I want to have the content of $_POST move from page to page but here is how my scripts work:

1) I have a form with a list of about 100 products that are listed with quantity text-boxes beside them. Users can fill out the number of each product they want and hit Submit.

2) They are then taken to a waver form that they have to accept.

3) After they click Accept they are faced with a form for contact information. They fill that out and click Submit.

4) Here is where it all happens. All information has to be displayed here. I would like to list all the products from the first page ( could be up to 200 products) and their contact information from page 3rd page. The problem is that I have lost all the information.

I don't really want to use sessions because there could be lots of products (up to 200).

I prefer using:


foreach($_POST as $name=>$value){
//skip the submit button
if($name == "submit"){continue;}
echo "<li>$name: $value<br>";
}

because of the large numbers of the products.

Is there any suggestions?
Kam

dreamcatcher

11:13 am on Mar 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When they click the first form, can you not store all the info in a database then retrieve it again on the last page? Maybe just store the username or something in a session variable, then query the db at the end with that variable.

and welcome to WebmasterWorld kamkaz.

dc

grandpa

11:50 am on Mar 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have a local Order Entry system that spans across 3 scripts, or pages. The first page accepts customer information, and contains about 30 pieces of information. This info is passed along to each successive script thru the POST array. What that means then, on each script I have to retrieve the values from the previous post and re-post them.

It's a bit of a kludge, but it works. It would be easier to store the values in a database (as dc suggested) or flat file. Easier from a coding perspective, as I have to make sure these values are in every POST, which means adding extra code. The second page contains 4 different forms (Previous, Next, Add, and Accept), so I've included those values in each form - even though they may not be relevant to that form. POST'ing just once without them means losing everything.

One option I've considered is to write a class that will 'hold' my values, but really, it would be much simpler to store these values in a table and retrieve them as needed.

The second page of my process can accept an unlimited number of items, and those are stored in a transaction table. Yeah, I got smarter as the process got more involved...

kamkaz

5:45 pm on Mar 6, 2005 (gmt 0)

10+ Year Member



Dreamcatcher: if I had that option I would have been home free. Thanks, it is the smart way to go.

grandpa: Sounds like what you have done is EXACTLY what I want.... So, can you help me out with some code or suggestions?

grandpa

8:01 pm on Mar 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well, you are going to have to assign the values to your POST array at every step of the way. With up to 200 items you'll be doing a lot of coding. I get the posted values in a foreach loop, then set those values to a variable that will be used in the next form.

This example is the basics, testing to see if a POST array element is set, then assign it's value to a new variable.

if (isset($_POST["USERID"]))
{
$wkUSERID = $_POST["USERID"];
}

Then in each form I add an input type for everything that will be passed along to the next page, just like it was done on the first form.

<input type="hidden" name="USERID" value="<?php echo $wkUSERID;?>">

I've got to admit, even handling as few as 30 variables like this can be a headache. If you can't access a database table your next best option would be to write them to a file and read that file back in the final process. I say this only because of the number of variables under consideration.

dmmh

10:21 pm on Mar 6, 2005 (gmt 0)

10+ Year Member



foreach($_POST as $name=>$value){
?>
<input type="hidden" name="<? echo $_POST[$name];?>[]" value="<? echo $value;?>">
<? }?>

erm, silly me, this wont work, help me out here, I have a big hangover :)

kamkaz

1:29 am on Mar 7, 2005 (gmt 0)

10+ Year Member



well actually i do not code the 200 items. They are beining populated from a csv file. the code is very small. most of it very dynamic. There has to be a way to take $_POST or another varible and pass it more than on hop or submit.
K

kamkaz

5:22 am on Mar 7, 2005 (gmt 0)

10+ Year Member



I guess the best way is to pump all the items to a flat file and then read them back in again when I am ready.....

dmmh

10:55 am on Mar 7, 2005 (gmt 0)

10+ Year Member



just pass them along the pages with:

<? foreach($_POST as $name=>$value){?>
<input type="hidden" name="<? echo $name;?>" value="<? echo $value;?>">
<? }?>

kamkaz

5:06 pm on Mar 7, 2005 (gmt 0)

10+ Year Member



PERFECT! That is how I will do it! Thank you very much!