direct page with onclick inside a form

0

Basically what I need is for a '' back '' button inside my form. It has to be inside for aesthetic reasons, the back button would be inline with the submit button.

I made a summary code:

    <form action="php/***.php" method="post">
        <p>DIGITE SEU NOME:
        <input type="text"  placeholder="nome" name="nome" id="nome"><p>

        <input type="submit">
        <a onClick="window.location='home.php';">
            <button style="margin-left: 10%" class="bt2" >Voltar</button>
        </a>
    </form>

But when I click the 'back' button it directs you to the action page on the form, not the onclick home page.

I managed to make this work on one page, but if I copy exactly the same code, it does not work on other pages. Very strange.

    
asked by anonymous 19.04.2018 / 15:58

1 answer

1

Very strange to use a button inside a <a> , because a button by itself already has the possibility to make a redirection. I would recommend instead of doing this, put in button a onclick="location.href='home.php'" and remove that <a> , which would be the most appropriate.

But the problem is that a type="button" is missing from the button because button is by default a submit button, so without type="button" , it will call the action URL form.

Do this: remove this <a> and leave the button like this, with type and onclick :

<button type="button" onclick="location.href='home.php'" style="margin-left: 10%" class="bt2" >Voltar</button>
    
19.04.2018 / 16:15