Searching did not find a similar question, so: How can POST data used by PHP to generate one page be passed from that page to another PHP generated page? I have:
- A form on page 1 which sends data to a PHP script via POST.
- Page 2 is generated by that script and shows one or more graphs generated by an external program using the entries on page 1 and the back end database. This page also has another form with options to re-generate the graphs with new options (e.g. zoom in on or truncate the graph(s)).
- If requested, page 3 will be generated with the same PHP script using POST data glued together from pages 1 and 2. Except for the graphs, its basic appearance will be the same as page 2.
- Pages 4, 5, 6 … should be generated in the same manner as page 3.
So, how can I put the POST data used to generate page 2 into the POST data for page 3?
EDIT: Due to organizational policy, cookies can’t be used (so sessions are not feasible). GET is undesirable because we don’t want the input to show in the URL.
I recall struggling with this issue long ago, wondering why I simply couldn’t redirect with a modified POST header. The reason is a redirect is actually considered a GET.
Regardless, you need to store the post variables in hidden fields.
I would recommend prefixing all your field names from each form so that its easy to tell them apart during your consolidation phase at the end.
Edit: As others have mentioned, persisting data using sessions is one possibility, but this becomes a very complex matter of maintaining temporary state which things like page refreshes or using the back button can make difficult to maintain. Unless you’re facing an extreme case, it’s much easier to persist data using fields since they survive refreshes and other browser behaviour much more easily.