Block form submission when clicking back

1

It may sound like a beast question, but I'm amazed that when I click the back button, the form is sent.

The code looks like this:

<form id="idform" method="post" onsubmit="return funcaodevalidacao(this);">
    <!-- conteúdo do form -->
    <input type="submit" value="Enviar"> <button onclick="window.location.href = 'URL'">Voltar</button>
</form>
<script>
    $('form').submit(function (ev) {
        ev.preventDefault();
        $(window).unbind('beforeunload');
        return false;
    });
</script>

What happens is this: when I click Back, it should redirect me to a desired URL, the form is SENT, and then it is redirected to the URL, which I do not understand is why the form is being sent.

I have tried the form described above to use preventDefault, disable beforeunload, return false, but the form is still sent.

How do I block this behavior? I'm testing on firefox.

PS: function: functionvalidation (this) is returning false for test purposes. The palliative solution I found was to remove the 'form' element, but I believe this is not the correct alternative. I checked the link link that disabling the element is also not possible.

    
asked by anonymous 10.05.2015 / 21:45

1 answer

0

Actually the form I was using in the above example adds a second submit call where it actually prevents the submitting form but still calls the validation function.

The most correct solution I thought of in this case was to add this script to the back button:

$('form').attr('onsubmit','return false;');window.location.href='URL'

This overrides the validation function that gave the impression that the form was being sent.

    
10.05.2015 / 22:15