2

I'm asking a question and the answer could help me a lot. When I'm filling my Django form, I press a validate button in order to store data form. Then, I am redirected on a new page (form resume page, home page, ...).

But in my browser, if I click on Back Button, my form is already filled with previous data and I can modify data.

My question is : How I can prevent browser from refilling form data when navigating back with Django ?

I found this Stackoverflow question : there

But the answer doesn't seem to work. It's an old answer and I'm supposing it exists an other way to do that ?

EDIT :

I used <form action="" method="post" autocomplete="off"> .. </form> and it seems working with Firefox.

Community
  • 1
  • 1
Essex
  • 6,042
  • 11
  • 67
  • 139

2 Answers2

1

This is front-end approaching but this would be easy to use if you can use JS and jQuery.

add this code below your HTML Template:

<script>
$(window).load(function() {
    $('form').get(0).reset(); //clear form data on page load
});
</script>

REF: https://stackoverflow.com/a/27544317/4741406

Community
  • 1
  • 1
Beomi
  • 1,697
  • 16
  • 18
  • I can use JS and JQuery but it doesn't seem to work. I added this code in my HTML template which display my Django form. I fill the form, I validate it, then when I use Browser back button, my form is still filled. – Essex Mar 01 '17 at 15:57
  • if change like this: `$(window).load(function() { $('#form_id').reset(); // declare form id });` still not working? – Beomi Mar 01 '17 at 15:59
  • `autocomplete` is good but some browser doesn't comply that. beware :) – Beomi Mar 01 '17 at 16:05
  • I tried with Firefox and Safari, it's ok up to now. I have to try with Chrome, IE ;) – Essex Mar 01 '17 at 16:06
  • always IE matters :( Chrome'll be fine! – Beomi Mar 01 '17 at 16:09
  • It's not a problem for me, because my Django application will be used with Firefox or Chrome ;) – Essex Mar 01 '17 at 16:12
0

You can disable the back button in your success page after filling the form. or reset the form : document.getElementById('form').reset(); this may help

Community
  • 1
  • 1
Lemayzeur
  • 8,297
  • 3
  • 23
  • 50