Input value is replaced after submitting

I have a php file that allows users to select conditions for a search page. After submitting data (with post method) the page will direct the user to the search-result page. I thought that it is likely that users want to go back to the "select condition page" to select a different condition for the search. There are two ways users can go back to the "condition" page. They can either click an anchor tag with "condition.php" or click on their browser's last page button (I'm using chrome right now).

So the problem or the bug comes out when I click browser's last page button. The value of the hidden type input for multiple condition selections are changed. It seems the latter value of inputs move up and replace the original value.

So, mainly I have two questions.

  1. What problem have I encountered?
  2. How to fix it?

the following is part of the html sample:

<form method="post" action"search-result.php">
<div id="category">
  <ul id="002001000">
    <li><input type="hidden" value="002001001">freestyle</li>                       
    <li><input type="hidden" value="002001002">frogstyle</li>
  </ul>
  <ul id="002003000">
    <li><input type="hidden" value="002003001">math</li>
    <li><input type="hidden" value="002003002">English</li>
    <li><input type="hidden" value="002003003">Biology</li>
  </ul>
</div>

<div id="location_list">
  <div id="region">
    <ul>
      <li rel="asia"><input type="hidden" value="Asia(Taiwan,Japan)">Asia</li>
      <li rel="america"><input type="hidden" value="America(USA,Canada)">America</li>
    </ul>
  </div>
  <div id="nation">
    <ul id="asia">
      <li><input type="hidden" value="Taiwan">Taiwan</li>
      <li><input type="hidden" value="Japan">Japan</li>
    </ul>
    <ul id="america">
      <li><input type="hidden" value="USA">USA</li>
      <li><input type="hidden" value="Canada">Canada</li>
    </ul>
  </div>
</div>
<input type="submit">
</form>

If I click "English", for example, submitting it, direct to search-result page, then I click "last page" button to come back to this condition page, the value of "English" and other values below would be replaced like this:

<div id="category">
  <ul id="002001000">
    <li><input type="hidden" value="002001001">freestyle</li>                       
    <li><input type="hidden" value="002001002">frogstyle</li>
  </ul>
  <ul id="002003000">
    <li><input type="hidden" value="002003001">math</li>
    <li><input type="hidden" value="002003002">English</li>
    <li><input type="hidden" value="Asia(Taiwan,Japan)">Biology</li>
  </ul>
</div>

<div id="location_list">
  <div id="region">
    <ul>
      <li rel="asia"><input type="hidden" value="America(USA,Canada)">Asia</li>
      <li rel="america"><input type="hidden" value="Taiwan">America</li>
    </ul>
  </div>
  <div id="nation">
    <ul id="asia">
      <li><input type="hidden" value="Japan">Taiwan</li>
      <li><input type="hidden" value="USA">Japan</li>
    </ul>
    <ul id="america">
      <li><input type="hidden" value="Canada">USA</li>
      <li><input type="hidden" value="Canada">Canada</li>
    </ul>
  </div>
</div>
<input type="submit">

Answers


You can put the terms in URL using GET form.

If you don't want them, to be visible in URL, you will have store them in session variables on server side.


When clicking the browsers back button, the browser might return a cached version. If you use this in your php page, it will not be cached.

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

That should solve it in the sense that it will get a fresh page from the server. Of course, you should still fill the fields on the server... Otherwise, it might have to do with the autocomplete for input fields. Use

<input autocomplete="off"/>

on your input fields and see if that fixes it!


Need Your Help

php 3 array loop to send single email from first array

php arrays email loops

I have three arrays. They are all index based arrays [0], [1]... They are:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.