Wednesday 11th November 2009

by Sajith M.R

A small tip for codeigniter programmers.

code-igniter-logo

If you use same controller for display view page and take action on POST, there is a problem may happen when you try to refresh the page after submit, the whole data get re-submit and creates problem.

It can be solved using session. If there is any POST form submit,

ie

if (count($_POST) > 0)

{

$this->session->set_userdata('post_data', $_POST );
redirect('same_controller');

}

else

{

if($this->session->userdata('post_data'))
{

$_POST = $this->session->userdata('post_data');

$this->session->unset_userdata('post_data');
}

}

This will solve the problem of resubmit !!!

Or simply you can use another controller for POST method and separate the form display using another controller (Normal way)

· · · ◊ ◊ ◊ · · ·

2 Responses to “Codeigniter – Post resubmit problem on refresh”

  1. D Whatley says:

    Thank you! I struggled with what to do about this for well over an hour.

  2. harman says:

    No need to use another controller for POST method.
    USE same controller with some method like..

    ———–your_controller———–
    index(){
    //YOUR controller DATA
    }
    save(){
    //GET YOUR POST DATA HERE
    //SAVE YOUR POST DATA
    redirect(‘your_controller’);
    }

· · · ◊ ◊ ◊ · · ·

Leave a Reply

وظائف 2011 تحويل العملات برامج برنامج تسريع التحميل برنامج الفلاش برنامج محول الصوتيات عربي hotel 2011 زيادة رواتب العساكر 1431