Page 1 of 1

$_POST variables disappear

Posted: Tue Jul 13, 2004 7:27 am
by primate
I have two forms on one page, but the output from the first form contains the second form so the second form isn't displayed until the first form is submitted.

The variables are submitted via POST and then POST is copied to $_SESSION[_POST].

When I run the first form I can see that $_SESSION['_POST'] contains the data I want and I can refer to it in the output of the first form. However when I submit the second form I lose the data from the first form and $_SESSION['_POST'] only contains the data submitted by the second form - but I still need to display some of the data submitted from the first form.

I could see why this would be the case if I was only referring to the $_POST superglobal but when I've copied everything to $_SESSION shouldn't the data from the second form just be added as new array elements to $_SESSION['_POST'] rather than it all being removed?

All the other data I need is still present in $_SESSION, its just the data in $_SESSION['_POST'] that is being reset for some reason.

I suppose I could rename the $_SESSION['_POST'] to something else and then refer to this but this seems messy since I don't undertand why its not working the way I though it should :?

Posted: Tue Jul 13, 2004 9:18 am
by kettle_drum
Its not messy to name it something else. Alternitivly put the data in hidden fields in the second form.

Posted: Tue Jul 13, 2004 9:18 am
by d3ad1ysp0rk

Code: Select all

//first post
$_SESSION['_POST'] = $_POST;

//second time
array_push($_SESSION['_POST'], $_POST);
That will make $_SESSION['_POST'] have ALL the variables from both forms, or you can do this:

Code: Select all

$_SESSION['_POST'] = $_POST;

//second submit
$_SESSION['_POST2'] = $_POST;
and access the variables either way.

Posted: Tue Jul 13, 2004 9:20 am
by primate
Great, I'll give that a try. :)