php question: passing $_POST values across multiple pages automatically

stndn

Golden Member
Mar 10, 2001
1,886
0
0
So i have three pages of php:
- page 1: user enters their information, blah blah blah.. let's assume they enter their registration information. The user clicks on submit button, and the information is sent using POST method to page 2.

- page 2: the $_POST values from page 1 is processed. Error checking, verification, and all that. If an error occured, the user is sent back to page 1, but we want to keep the values they typed intact. That means, if they entered their birthday on page 1, we found out that the birthday is invalid on page 2, we want to send them back to page 1 with their incorrect birthday value still filled in the appropriate <input type="text">

- still page 2: if there is no error, we want to automatically forward all the $_POST values to page 3 to be processed even further.

- page 3: get the $_POST value from page2, which was obtained from page1 when the user hit the submit button.


The question would be: how to accomplish that?

The catch: The user should not be doing anything on page 2. They are not required to click on another submit button to pass the $_POST values to the next page. All they do is click submit on page 1, and our PHP script automatically process the $_POST values on page 2, and forward the $_POST values to be used again on page 3.

Is there an easy way of doing this? Or do we have to use a pop-up of some sort? Javascript? Cookies? Etc?

Any suggestions so that the user don't have to do anything on page 2?

Thanks, and hopefully it's not too confusing....
 

screw3d

Diamond Member
Nov 6, 2001
6,906
1
76
I think the easiest way is to go back like the way you click on "back" on the browser.. that means you shouldn't even have to submit your data anywhere..

I could be totally wrong though :eek:

Edit: I can't remember what is the PHP function that does this.. but in Javascript it would be javascript:history.go(-1) or javascript:history.back()
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
screw3d: that will only work if the user makes mistakes in the form, and we need to make them go back to page 1 and edit their entries. But what if they submitted the correct values? We want them to be sent to page 3 automatically with the $_POST values (from page 1) still intact.

hmmm... my friend suggested that i use javascript to 'auto submit' the form generated on page 2 and send the form values to page 3 ..
that might be the way we'll have to do it ... but oh well, we'll see

any extra ideas?
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Well if the user isn't going to be doing anything on page2, why not just combine page2 and page3 into one page?

Maybe i'm misunderstanding what is going on on page2 tho...
 

screw3d

Diamond Member
Nov 6, 2001
6,906
1
76
Originally posted by: MCrusty
Well if the user isn't going to be doing anything on page2, why not just combine page2 and page3 into one page?

Maybe i'm misunderstanding what is going on on page2 tho...

Yeah.. that's what I'm thinking too..

You can either combine the pages, or make a bunch of hidden fields and store the data like:

<input type="hidden" name="test" value="<?php $_POST[test]; ?>" />

and on page 3, you can pick the values up from the hidden fields..

Though I'm sure someone will come up with a better solution :)

edit:

So the final logic would be something like:

- validate

if (validate not ok) use javascript to go back to page 1

else if (ok) store the data in hidden fields then submit form to page 3


 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Something like:

<input type="hidden" name="test" value="<?php echo htmlspecialchars($_POST['test']); ?>" />
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
The reason we cannot combine page 2 and page 3 is that we will be doing some extra processings on page 2, and a different processing on page 3.

Actually, now that i read my own question and the answers you gave, i get more confused as to what we're trying to accomplish with this auto-submit .... [ ashamed ]

I guess i'll have to talk to the project-giver and ask for more details again as to why we need this mess in the first place. But i'll keep in mind the suggestion with javascript for returning to page 1, and hidden fields for redirecting to page 3.

Thanks all -)
 

kuljc

Golden Member
Apr 7, 2004
1,845
0
0
I've been doing a lot of this kind of stuff on my website which will be up and running soon. And well it's been a long and hard battle to teach myself this stuff, and so I'll help ya out if you want to do it like me.

I use cookies so hopefully that'll be availiable to you too. Either that or sessions which i hear are similar to cookies.

on page 1:
you input info... and on that same page w/ javascript you're able to verify if the info is correct.

on page 2:
you process the information w/ php or whatever you want to use. Store it in a cookie w/ some character to separate each item.

have it redirect to page 3 automatically.

on page 3:
w/ php you can use a command called explode or another one similar to it and it'll break whatever you stored in the cookie into an array.

do whatever you need to do w/ that.
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
Hmmm.. havent thought about cookies to do that.
We can probably use cookies to forward the $_POST values.. Although i'm not sure if it will be feasible since one of the forms we want to process have about 30+ input fields... and inserting them as one lengthy string could give us troubles.

but we'll definitely look into it.

But first thing first, i guess i need to have a talk with the project manager again as to what it is we're trying to accomplish. I've been thinking about too many ways to solve this problem i've forgotten why we need it done in the first place .... -(