Previously entered form data is re-entered automatically

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JackD
Forum Commoner
Posts: 62
Joined: Sat Dec 12, 2009 6:25 pm

Previously entered form data is re-entered automatically

Post by JackD »

I have the code:

<div id="Search_Form">
<form method="post" name="Keywords" >
<p class="style1">Search For: <input type="text" name="KWs" style="width: 354px" /></p>
<p><input type="submit" value="Search!" /></p>
</form>

if ($_POST[KWs])
{ echo "Find: " .$_POST[KWs] . "<br />"; }

If I enter the page and type in a value for KWs, the next time I return to the page, the value for KWs is automatically applied rather than starting over with a "clean" form. I have tried unsetting $KWs and putting value="" into the form, but nothing seems to keep it from entering the previous text automatically.

Is there a way to always force a "clean" start?
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Previously entered form data is re-entered automatically

Post by McInfo »

This appears to be a result of using your browser's back button. Remembering your form inputs is a "feature" of your browser that is related to the page history.

To fill the form with its default values, you can include a reset button (<input type="reset">) in the form or you can request the page again through a link or by entering the URL manually.

Using JavaScript and the onload event is not an option because in some browsers (Firefox) the onload event does not fire when returning to the page via the back button (it does in Internet Explorer, though). The onunload event is not an option either because the form would be cleared before it is submitted.

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Thu Jun 17, 2010 3:56 pm, edited 1 time in total.
JackD
Forum Commoner
Posts: 62
Joined: Sat Dec 12, 2009 6:25 pm

Re: Previously entered form data is re-entered automatically

Post by JackD »

Sorry for this post, guys, it turns out it was the browser cache causing the problem. When I clear the cache, it no longer is a problem.

Thanks for tolerating a newbie.
Post Reply