Should I be doing this for form validation? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: Should I be doing this for form validation? (/showthread.php?tid=67287) |
Should I be doing this for form validation? - n2fole00 - 02-05-2017 When I first started using CI I basically read a bunch of tutorials online. One of these tutorials (I can't remember which), had form validation rules defined in the model, which I liked because it was something I was used to doing in asp.net mvc. I've been doing this for a while, but just realised, I can't seem to find this way in the form validation docs. I think an example is clearer Model PHP Code: public $validate = array( Controller PHP Code: public function create() So I was a little worried and wanted to confirm if this is cool, or should I only stick to what's in the examples from the docs? Another thing that got me confused was passing a bunch of arrays to set_rules was ok, but passing one array didn't work for some reason. For example, if I just wanted to update the description field and pointed to a specific array just for just that, run() always returned false PHP Code: public function update_description() Have I passed the wrong thing here? Thanks. RE: Should I be doing this for form validation? - pdthinh - 02-05-2017 I think there's no problem with your approach. For the second question, validation rules should be an array of array so you should try: PHP Code: public function update_description() |