Using POST method to display values on a different webpage


#1

I’m trying to using the POST method to retrieve information entered into two checklists on a webpage, display it on the next page and keep it stored (in variables?) to be sent to me via email when contact information is entered on the next page when the submit button is clicked. I’m not sure how to go about doing this and I’m also not sure if I need to have a PHP file solely for this. This is my first web development project and I’m very new to PHP and HTML.


#2

How much code have you got so far?

Each time you submit a page, the form contents will be sent as part of the $_POST array. If you want to use those variables and the contents of a form on the second page, you need to consider how you will keep both sets. One way is to have PHP (or another language) “draw” the second form, and include the contents of the first form entries as hidden fields in that second form.


#3

I’ve yet to write any, I should’ve included that in the question, my apologies. So what you’re saying is that I will have to create another array and store all of the variables from the first page (which are initially stored in the _POST array) and then store the values from the form on the second page as well? Would I be able to just keep the two separate arrays? Or does the _POST array get overwritten each time you use the POST method? Also, as I am still very new to server side scripting, does the array get overwritten each time the webpage is loaded? I’m assuming it would have to be for each new visitor to the page.


#4

If you use normal <form> tags*, what gets submitted is whatever input fields are contained within the form tags, into a $_POST array if that’s the method you choose. So, when you submit the first form, whatever script is used to process that form will get all those variables, but it won’t automatically pass them on. Hence, you use that script to draw the second form, and include those variables as hidden input fields in the second form. That way, the second form on submission will contain any new fields, and the old ones that you put in as hidden fields.

The array is created as part of the submission process, not when the webpage is created. Every time an individual user submits the form, the server starts an entirely new process for the script defined in your form “action” parameter, which receives those form variables completely separately from any other user of that script. That’s the sum of what happens to that data - if you want to retain it for another form or script, you have to do it manually, either in the way I described, or with cookies or session variables or by storing it in a database.

(* I’m simplifying - with JavaScript you can do other stuff, but if you’re starting out, stick to standard HTML and PHP for now).