Using the same controller method for form display and processing

One of the common issues with MVC controller is to use the same controller method to show a form and then process it’s content, once we receive POST.

We detect whether there are any POST variables available with if ($this->input->post()). If available we process the form with POST data otherwise we show the form. You may have the form/file upload validation here.

public function register() {
    global $data;
    if ($this->input->post()) {
        //process form here
    } else {
        //display form here
    }
}

 

Share