-
Form submit question
I've got a simple form on my page (name, email and how you found me) which works fine and writes the details to a txt file once the form has been submitted. However, I seem to be getting people you submit the form and then refresh the page (for whatever reason) and their details get added again to the txt file.
My question is: Is there a way to check if a person refreshes the screen and if they have bypass the writing to the txt file routine?
-
Re: Form submit question
There is a way to prevent it from happening in the first place. Have the form submit to a processing page an send a redirect header after processing.
As for checking you could open the text file and look for the the appropriate name / email combination but that would be an intensive process.
-
Re: Form submit question
Using a database is out of the question?
-
Re: Form submit question
Whether you use a database or not you will still have the problem of lingering POST data unless you use a 303 redirect from your POST handler page.
PHP Code:
header('HTTP/1.1 303 See Other');
header("Location: http://{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_NAME']}");
303 responses are not cacheable, so navigating backwards from the redirected response will function as expected.
-
Re: Form submit question
I never thought of using the redirect before. I've been using a SELECT query to see if the same "post" was saved by the same user/ip/email/message/etc. :o
-
Re: Form submit question
You should use a composite primary key for that. That will save you one query per post.