Welcome Guest, Not a member yet? Register   Sign In
On reload the data is submitted again.
#1

[eluser]goldenray[/eluser]
hi!
I am new to CodeIgniter. When I submit a page and reload the page again, the database get updated again. How can I stop it from happening?
Is there something similar to checking ispostback in asp.net. Please help!!
#2

[eluser]nmweb[/eluser]
What I usually do is that when a form is submitted and it validates I perform the database update and then throw a redirect to some other page.
#3

[eluser]goldenray[/eluser]
Thank you for your suggestion but is there any other way to do this?
#4

[eluser]Pascal Kriete[/eluser]
You could generate a unique form token and put that in a flashdata variable so it's only valid for one request, but redirect is the better choice. Even redirecting to the same page will do the trick.
#5

[eluser]goldenray[/eluser]
Thanks for your assistance. But I have only one controller which is the heart of my application. In that case, how can I handle that. Can you give some code example of how to check it.
Thanks in advance.
#6

[eluser]Sarfaraz Momin[/eluser]
Well once the form is submitted you can unset the post variable and set a variable with some value to know the form is submitted. If the user reloads the form, Firstly you would check if the value of that variable is set or not. In case it is you would just set the value of the same variable again and show some message to let the use know that the form is already submitted. Try to use this login and it should work fine.

-Sarfaraz
#7

[eluser]ontguy[/eluser]
I found a javascript approach on this page:

http://www.orafusion.com/js_demos/jstips_10_demo.htm
#8

[eluser]Pascal Kriete[/eluser]
One controller - oh geez. Ok, just do what sarafaz suggested (minus unsetting the post variable, cause that doesn't work). You will still need to redirect.

Something like this:
Code:
if( ! $this->session->userdata('submitted') )
{
// Not submitted yet - normal validation stuff here

    if($this->validation->run() == FALSE)
    {
        // Load page with form
    }
     else
    {
        // Add the data to the db

        // Set the session variable and redirect back here
        $this->session->set_userdata('submitted', 1);
        redirect($this->input->uri_string() );
    }
}
else
{

// Submitted - show whatever

}




Theme © iAndrew 2016 - Forum software by © MyBB