I'm working on an extension. It has an admin.php and admin.tpl with a html FORM. so admin.php make both data submission and POST data reception and processing ... like I have seen most of the extensions are doing.
I observed in my extension that if I refresh the page after the successful POST, the data is processed again.
This is a well know issue for developers:
https://en.wikipedia.org/wiki/Post/Redirect/Get
https://stackoverflow.com/questions/632 … d-f5-ctrlr
I wonder are they any know methods/functions already implemented in Piwigo that can prevent this?
I have studied some plugins code and didn't find anything.
Last edited by eliz82 (2021-02-20 16:30:10)
Offline
Pseudo code:
On submission, check for existence of form field ($_GET / $_POST)
If exists, then set a new 'hidden' form field in form
On 'refresh/resubmission' check for this new, hidden form field
If exists abort unwanted action
This is just one way I've handled these things - I'm sure there are much more and much better methods.
* Disclaimer: I am not a programmer, but sometimes I play one on the Internet.
Offline
so the code of admin.php should look something like this:
$repost = false; if (isset($_POST['submit'])) { if (isset($_POST['repost'])) $repost = true; } else { //do your normal data processing } } $template->assign( array( 'MY_PREFIX_REPOST' => $repost, ) );
and admin.tpl
<form method="post"> {if $MY_PREFIX_REPOST} <input type="hidden" name="repost"> {/if} <button name="submit" type="submit">Start</button> </form>
interesting method, thanks. I must test this to see if it works. do you have a plugin in in which you implemented this method?
Offline
That looks about right to me.
I don't have any plugins, but have used this method in many PHP forms.
Offline
I have found a thread with similar issues
https://piwigo.org/forum/viewtopic.php?id=28865
Offline
PS: don't forget to use the Piwigo token and check_input_parameter :)
Offline