CodeIgniter Forums
Form validation in different controllers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Form validation in different controllers (/showthread.php?tid=70631)



Form validation in different controllers - glorsh66 - 05-05-2018

I want to make different controllers to show form and validate form, but at the same time i want to be able to show a validation message.
So for instance i  want to have a log in form two different places 
1) special page: site/login
2) anywhere on the site in the right top corner of the page 

And i want to share validation logic between them.
So i want two this forms send data on the same controller 
POST - user/validate
And at the same time if password is incorrect (or something else) show a validation error (in different places).


And second part of my question is How can i implement forms with validation on the one page.
Let's imagine a situation.

It's something like a forum - and i have 3 forms on one page -
1) mini login in the right top corner of the page.
2) main form for submitting your post
3) additional post for commenting system

And i wanna validate data from those forms (of course on the different controllers to avoid code duplication) and show validation error on the needed form (so if the password is wrong show it near the form, when you can write a password in, and on the form where you writing a commentary). 
And simultaneously how don't lose entered information? (or is it impossible and you need to implement using JavaScript and store data temporally in cookies?)


RE: Form validation in different controllers - glorsh66 - 05-05-2018

I asking this because in the documentation (that honestly is the best one in comparison to all other frameworks) there is the only one example, that shows how to use form validation on the one controller - both rendering and validation (using IF statement to discern if form has been sent or have not), but there is not a word about using it in different controllers or at least different functions of the same controller (and i honestly think for this example it makes absolutely no difference).

And code in controller can quickly become a complete mess if you write everything in one controller, especially if your page contains more than one form.