Jump to content

Test POST (clearing the POST cache)


Recommended Posts

I'm testing with Chrome. I am writing a directory search program and when I choose the directory (just a text input box) I post this back to the same app:

<form action="tedit.php" method="POST">
<div style="width:30em;">
<label for="directory">Directory to Search</label>
<input type="text" name="directory" id="directory" value=""/>
<div style="clear:both;">
<input type="submit" name="submitButton" id="submitButton" value="Submit">


and when I process the post, I look at $_POST["submitButton"] and $_POST["directory"].


However, as is the case now, when the directory is nonexistent, I cannot figure out how to get rid of this data. I've tried unset() and $_POST["directory"]=""; but neither seems to work.



Link to comment
Share on other sites

The problem occurs because the recorded information in the browser's history for the URL is a form submission. When you navigate back to that URL or refresh the page the browser attempts to perform the action it has recored for that URL. There are two things you can do to fix this -


1) After you have successfully processed the form submission, redirect to the same URL. This will cause a GET request for that URL to be recored in the browser's history and it won't resubmit the form data when you navigate back to that URL.


2) Store a value in a session variable that indicates that the form has been processed and skip the form processing code as long as that session variable is set.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.