How to keep input values when user moves to another page [duplicate]

0

Well, I set up a very simple form to explain my problem.

<?php
$action = filter_input(INPUT_GET, 'action', FILTER_DEFAULT);

if ((!empty($action)) && ( $action === "add")) {
?>
    <script>
        alert('ERRO');
        window.history();
    </script>
    <?php
}
?>


<form action="form.php?action=add" method="post">
    <input type="text" name="nome">
    <input type="text" name="email">
    <input type="password" name="senha">
    <input type="submit" name="enviar" value="enviar" />
</form>

When there is an error in my form I send a alert to the user and it is redirected to the previous page to correct the error. The problem is that all form data is lost when it returns. Is there any way to resolve this? A way in which data is kept and only deleted when the form is correct?

    
asked by anonymous 24.03.2017 / 20:32

1 answer

1

Change% of% by window.history() (equivalent to clicking the Back button of the browser), when you use the back button of the browser or even the window.history.back() function, the browser itself recovers data from back the request came from <form> itself)

<?php
$action = filter_input(INPUT_GET, 'action', FILTER_DEFAULT);

if ((!empty($action)) && ( $action === "add")) {
?>
    <script>
        alert('ERRO');
        window.history.back();
    </script>
    <?php
}
?>

<form action="form.php?action=add" method="post">
    <input type="text" name="nome">
    <input type="text" name="email">
    <input type="password" name="senha">
    <input type="submit" name="enviar" value="enviar" />
</form>

About the API history : link

    
24.03.2017 / 21:53