Welcome Guest, Not a member yet? Register   Sign In
problem with 'refreshing the page'
#1

[eluser]akkumaru[/eluser]
hi, all,,

i have a function in a controller that inserts or updates something to the database, and then gets data to the view.

my problem is every time i refresh the page, the insert or update operation will be done again,, and i need to prevent such action.

What strategy would be best for this,?

my best guess is to flush the post data sent by browser so the 'refresh' action without actually filling the form may not insert or update the database,,

but, i just don't know how to do this,,
please help,,?
#2

[eluser]Pascal Kriete[/eluser]
The easiest way to deal with this is to simply redirect. So your insert function really just runs a query and then redirects the user to the list of entries (or wherever they came from).
Code:
function insert()
{
    // validation and sql query
    redirect('page');
}
#3

[eluser]akkumaru[/eluser]
i see,,
but, is there any way to flush the POST data,,?
#4

[eluser]obiron2[/eluser]
Put a hidden field in the form with a unique value and save that to the database on 1st save.

Check for it before saving and if it is there, you know that this is a re-submit.

Obiron
#5

[eluser]Erwin Setiawan[/eluser]
Why your function for insert update not placed in model?

hmm.. my be you can use

Code:
if(isset($_POST['submit']))
{

}
#6

[eluser]akkumaru[/eluser]
@Erwin
i use something like that

i know i should just redirect the page,,
but still i want to know if there's a method to flush/clear the POST data




Theme © iAndrew 2016 - Forum software by © MyBB