0
Well, I rode a form
very simple 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 one alert
for 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?
this does not solve my problem, because in some input I already use the
value
to upload information.– Hugo Borges
If you understand how it works you will understand that you can solve yes. Regardless of different situations, the technique is the same. Note that you can still resolve with Ajax, Cookies or Sessions. Ajax may be more interesting because it does not redirect the page. Thus the data persists, in addition to saving data traffic.
– Daniel Omine
What if instead of window.history you use window.Location? then add the fields that were inserted as query string... with that being they come you load in your form... something like window.Location= Document.referrer + '?index=1';
– h3nr1ke
@h3nr1ke, the form action is leading to the same page.. No need to redirect. Just take the amounts of $_POST... The edition of the title defaced the context, giving rise to misinterpretation.
– Daniel Omine