1

I have a registration form. If a user fill out all the required fields.

And when he reloads the page with out submitting form, the fields contain the values entered by the user. I want them to be empty as they were on first page load. I have given value="" to the fields but they still contain the previously entered values.

<form id="registration_form" name="registration_form" method="post">

<input name="first_name" id="first_name" value="">
<input name="last_name" id="last_name" value="">
<input name="user_email" id="user_email" value="">
<input name="status" id="status" type="hidden" value="active">

</form>
Hassan Sardar
  • 4,413
  • 17
  • 56
  • 92
  • @웃웃웃웃웃 There is no code to ask for. He is asking, generally, how to implement such a goal. – BLaZuRE Jan 01 '14 at 06:40
  • @웃웃웃웃웃 You asked for code, here it is, please check my post – Hassan Sardar Jan 01 '14 at 06:44
  • 1
    There is no server-side way of removing cache. Why would a client want to allow a server to control its cache, deleting everything in there at its whim or allowing a server to view the cache? You can, however, perhaps, pass a new hash per load of the page for the id of each field, though that may not be reliable. – BLaZuRE Jan 01 '14 at 06:46
  • This isn't caching, which refers to the HTML content of pages. This is form auto-fill. – Barmar Jan 01 '14 at 06:58
  • @Barmar So how can I solve this auto-fill issue ? – Hassan Sardar Jan 01 '14 at 06:59

3 Answers3

3

This is form auto-fill, not page caching. You can disable autocomplete with:

<form id="registration_form" name="registration_form" method="post" autocomplete="off">
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thanks for the solution but it didnot worked for the hidden fields – Hassan Sardar Jan 01 '14 at 07:03
  • There must be something else going on that you're not showing. – Barmar Jan 01 '14 at 07:04
  • Aren't hidden fields supposed to be filled in automatically? The user can't fill them in himself. – Barmar Jan 01 '14 at 07:05
  • Basically its a whole huge module, hidden fields are maintain using javascript, but I am saying that, if i made simple html form with hidden fields its not getting empty by page reload, when I press Ctrl+F5 then it become empty – Hassan Sardar Jan 01 '14 at 07:11
  • 1
    I can't explain that. Are you sure you're reloading the page, not using the back button? Browsers vary in what they do when you use the back button, some will put back the form contents. – Barmar Jan 01 '14 at 07:13
  • I just press F5 button, it reloads the same page with same values, simple – Hassan Sardar Jan 01 '14 at 07:15
  • can you give a link to the page? – Barmar Jan 01 '14 at 07:20
0

If you want to remove cache as you asked first (before edit), There are many ways,

Adding meta tag on page

<meta http-equiv="Cache-control" content="no-cache">

By redirecting using javascript,

window.location.href+'?eraseCache=true';

These are discussed in an other topic here.

If you just want to delete the values on the fields,

use

document.getElementById('text_box_id').value="";

on the top inside the head tag.

Community
  • 1
  • 1
Vishnu R
  • 1,859
  • 3
  • 26
  • 45
0

Remember to add autocomplete="off" to your form. This is auto-complete issue with some browsers, then you need to use id trick, every time you're loading the registration page, let say:

http://localhost/register.php

you can try it manually to see if it's works for browsers you've been testing, for example load this address on your browser and see if it still auto complete the form:

http://localhost/register.php?id=23

you can add id=anynumber, this happens to work perfectly, I do this with my CSS imports. To make it more PHP you can write some code like this:

$number = rand(1,100);
header("Location: register.php?id=$number");

Hope it helps

negative0
  • 459
  • 4
  • 10