Note that there are some explanatory texts on larger screens.

plurals
  1. POAfter form submit, show new values inside inputs instead of cached ones
    primarykey
    data
    text
    <p><strong>ATTENTION: This was not a cache problem, nor a server misconfiguration, nor a browser issue. After careful investigation, I've found the problem was due to a problem in my code:</strong> Stupidly enough, my select query that populates the fields preceded my update query, causing the form to always show the values before the update. After reloading, of course the newly updated values would appear, causing me to look in the wrong direction. </p> <p>This question however shows a nice overview of all the possible solutions when facing a caching problem.</p> <hr> <p>I'm building an application on which there are forms, populated by values from a database. The user can change the input values of the form. After submitting (not via AJAX), the new values are saved to the database AND the same form is displayed again, this time containing the new values, loaded straight from the database. However: my browser (Chrome v27.0.1453.116m on Windows 7) caches the old values. The new values are only shown when I navigate to my page again.</p> <pre><code>&lt;form id="edit_form" class="form" action="http://the.same.url/" method="post"&gt; &lt;input type="text" name="example" value="&lt;?php echo $value_from_database; ?&gt;" /&gt; &lt;/form&gt; </code></pre> <p>I have come across several solutions, none of which quite solve the issue:</p> <ul> <li>Setting an attribute <code>autocomplete="off"</code> on the form tag: this does not seem to have effect.</li> <li>Setting an attribute <code>autocomplete="off"</code> on the individual input tags: this also does not yield results, even in combination with the above solution</li> <li>Resetting the form with JavaScript on page load: this gives some results, but apparently does not affect radio buttons and others.</li> <li>Preventing caching of pages via meta-tags, as suggested here: <a href="https://stackoverflow.com/questions/1341089/using-meta-tags-to-turn-off-caching-in-all-browsers">Using &lt;meta&gt; tags to turn off caching in all browsers?</a> Also, preventing caching via .htaccess or php headers does not have effect.</li> <li>Trying to cache-bust by adding a random number to the action-url, as suggested by comment below by Miro Markarian</li> </ul> <p>Here is an overview with proposed solutions: <a href="https://stackoverflow.com/questions/2699284/make-page-to-tell-browser-not-to-cache-preserve-input-values">Make page to tell browser not to cache/preserve input values</a></p> <p>What are my options? If possible, I would like to avoid posting my form asynchronously. It starts to look as if I have no other choice. Any input is appreciated.</p> <p>Please note that this behavior also appears in other browsers, such as IE10.</p> <p>My page title is the same as the value of one of the inputs in my form and also does not change upon submitting a new value, imho we can determine this to be a caching issue.</p> <p>Google Chromes' Web Developer plugin shows me the following headers:</p> <pre><code>Pragma: no-cache Date: Sun, 30 Jun 2013 09:44:12 GMT Content-Encoding: gzip Vary: Accept-Encoding Server: Apache Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Connection: Keep-Alive Keep-Alive: timeout=15, max=100 Expires: Thu, 19 Nov 1981 08:52:00 GMT 200 OK </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload