Reputation: 4523
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>
Upvotes: 1
Views: 4634
Reputation: 1879
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.
Upvotes: 0
Reputation: 459
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
Upvotes: 0
Reputation: 782488
This is form auto-fill, not page caching. You can disable autocomplete with:
<form id="registration_form" name="registration_form" method="post" autocomplete="off">
Upvotes: 3