Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
727 views
in Q2A Core by
Hi,

I have a list of items and a delete button.

item1

item2

...

ItemX

deleteBtn

After I clicked deleteBtn, it will delete the first item which is item1.

Then if I refresh the page, it will continue to delete item2...

I realized that it was because everytime it loads this page, it will do this:

if(qa_clicked("deleteBtn")){

     // do delete opreation

}

And if after clicking, no other button is clicked, qa_clicked("deleteBtn") will still be true, so it will keep deleting things.

 

Is there any way to solve this problem? Any suggestion or advice is also very much appreciated.

Thank you !
Q2A version: 1.6.3

1 Answer

0 votes
by
selected by
 
Best answer
If you refresh the page the POST is sent again to the server. Instead of refreshing click into the URL bar and hit enter. This way the URL is loaded fresh without any POST data.

Noramlly your browser should warn you about sending the POST again. My Firefox does. Maybe you have switched off this warning?

Kai
by
Thank you for your advice !

You are right. There is a warning while refreshing and if clicking yes, the POST data will be sent again so the operation will be done again too.

So I changed my code. If a DELETE button is clicked and the operation succeeds, I use qa_redirect() to load into the page again and send data by $_SESSION['data']. In this way, user can refresh the page without posting the data again. This is just for user experience consideration. Sometimes people refresh the page as a habit.\

Anyway, thank you for your quick response !
...