Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sticky Forms/$_POST array

Status
Not open for further replies.

james6848

Technical User
May 10, 2004
23
GB
Hi,
I've got a standard HTML form (eg. 'contact.htm') that submits to a PHP page, which in turn emails the details to me and inserts into a MySQL db. Everything is working fine, except I can't create a sticky form when a user needs to resubmit. I've tried everything the books say (ie inserting the relevant $_POST[] variable in the form's 'value' bit and changing the page to .php) - but no joy if the page is returned to via a standard a href="contact.htm" command. I'm wondering whether the $_POST array is still set when the HTML form page is reloaded, or if it is deleted each time. I've noticed that using the browser's 'back' button DOES retain the form's details - is there a PHP way to operate this?

Sorry for the long-winded explanation!
 
The standard method for "sticky" forms is to POST the form back to the same page, i.e. you put your contact form is contact.php and post to contact.php. That way, you're inserting the POST data into the form on the same page you're using to process it. Posting to a PHP page and then redirecting back to the HTML page won't work. Well, you could make it work using tricks like passing the form data in the query string or by using the header() function to add post data to the HTTP request, but those would be ugly hacks.
 
contact.htm is a plane html page, php will not be processed here, first change the contact.htm to a php page so next time this page is whown will use the POSTed vars.

Cheers.
 
Thanks guys. So, to sum up, the $_POST array is reset each time the page is exited, right?
 
To be technical, $_POST only exists while the PHP script is running. When a script starts, PHP populates values in the superglobal arrays from values provided to PHP by the web server. Once the script stops running, all variables in the script no longer exist.


There are some workarounds which use serialization of the variable to a more permanent storage medium, the most common in PHP being when $_SESSION is stored to the filesystem when the script ends.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks. I think the main problem is that I thought I could get away without using include() and require() functions! Back to the drawing board...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top