1
Well I’ve put together a very simple example in php. I have to identify when it is sent by button and when it is sent when the user returns to page.
The problem is, if you submit the form 2 times and then click the back button it says that the method was POST, which was not because the user clicked back.
You have some way of handling it?
Follow the simple example.
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$txt = "POST";
} else {
$txt = "GET";
}
echo $txt;
?>
<br><br><br>
<form action="form.php" method="post">
<input type="text" name="ae" value="ae" />
<input type="submit" name="enviar" value="enviar" />
</form>
In fact the method was yes POST, because the return only repeated the last action that had been a POST. Maybe you can set a field by clicking Ubmit that allows you to identify if the call came from
click
or not. As the return will submit the same value, you can set the date/ time, something so that helps you identify that was an authentic post by the button. Just a few ideas that might help you.– Ricardo Pontual
I could put together an example with the date and time?
– Hugo Borges
@Hugoborges, usually when you receive a form in the back-end you should process it and at the end of it give a redirect to the user, preventing it press F5 or turn the page and forward the form.
– jlHertel
@jlHertel the problem and that I can not use the
redirect
because it has to be using before anyout-put
and I run some echo before submitting the form.– Hugo Borges
@Hugoborges, I think you don’t understand the flow. The correct one would be: 1 - Shows page with form. 2 - Received the POST form, processes and at the end of the redirect to another page, can be the form again. If in the middle of processing the form you have
echo
, you can use the functionob_start
to prevent the exit of the controls.– jlHertel
@jlHertel thanks for the help, took a look at the documentation of the
ob_start
and solved 100% of my problems. Thank you– Hugo Borges
@jlHertel ok. I used the
// Inicializa o buffer de saida
ob_start();
at the beginning of the archive and the// Descarrega o conteúdo interno do buffer
ob_end_flush();
at the end, that way I can use the redirect wherever I want.– Hugo Borges