Welcome Guest, Not a member yet? Register   Sign In
Best pratice form Form with validation errors

first sorry for my english
i'm upgrading a site from ci 2.1.6 to ci 3.1.5
the previous dev made 2 functions in a controller for form handeling
1 for loading the login view and 1 for the login process
if a form_validation with errors occured we were redirected by redirect() from the login_process function to the first login_view
in CI2 form validation errors where available after redirect, now IN CI3 it doesn't work anymore with this kind of setup
was this a bad practice?

how do we have to recode this stuff? only one controller as on the doc?

i tried this kind of code:

class Form extends CI_Controller {

       public function index()
               $this->load->helper(array('form', 'url'));


               if ($this->form_validation->run() == FALSE)

my problem is that the first view (index in the above sample code) is after a  post form, so when we are redirected to the the page we have a form validation error showwing

how can i fix that?

Your guess is as good as any. What I mean is, 10 different people can tell you 10 different ways of doing this, so as a developer you should just come up with your own strategy. For me:

1) I post to the same method that generated the form/view.
2) Form validation and processing only occurs if CSRF token is good and request method is POST.
3) Errors, or a success message is sent to the view using $this->load->vars().
4) It is not desirable to have all forms repopulate, and in that case simply kill the post vars.

Theme © iAndrew 2016 - Forum software by © MyBB