Welcome Guest, Not a member yet? Register   Sign In
Calling a controller after validation error
#1

[eluser]palaniappanc[/eluser]
I generate my pages by calling multiple views (header, form, footer). How would I get this page back after validation? I don't want to call all the views again (code duplication). Is there a way to call a controller (something like $this->call->controller('formpage') on form error, passing all the error messages to it and it's views?

Thanks.
#2

[eluser]xwero[/eluser]
I'm not sure how your code looks like but if you put your view calls in the method you can do
Code:
function page()
{
   $this->load->view('header');
   if(count($_POST) > 0)
   {
       $this->load->library('validation')
       // rules
       if(!$this->validation->run())
       {
            $this->load->view('errorform');
       }
       else
       {
            $this->load->view('successform');
       }
   }
   else
   {
       $this->load->view('form');
   }
   $this->load->view('header');
}
If you don't use other views but display the information in the same form you only have to change the content of the second parameter in the view method that displays the form.
#3

[eluser]palaniappanc[/eluser]
xwero, thanks.

I didn't want to call multiple views though, and have figured out a method to do this. In the formpage controller, I have the function 'index' (that displays the form, calling multiple views) and a function called 'validate' which does exactly that. On form error, the validate function just calls the index function. This way, the error variables are available, and I don't have to call multiple views.




Theme © iAndrew 2016 - Forum software by © MyBB