![]() |
Form Validation Problem - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Form Validation Problem (/showthread.php?tid=34275) |
Form Validation Problem - El Forum - 09-24-2010 [eluser]Unknown[/eluser] Hey all, I'm new to Code Igniter, and I really like it so far. I've just run into a strange problem which I can't seem to solve; it's not "mission-critical" or anything, but it IS infuriating me! I've a got a form, created with the form helper, and I'm using the form_validation library to validate it. My problem is this: my form is basically an array of checkboxes, named 'perms[]'. The form is created without incident. I don't want users to be able to select NO checkboxes, so I add a rule in the controller that says perms[] is required. This works fine. The rule executes and people cannot submit an empty array. BUT the error accompanying a fail NEVER shows. I've tried using validation_errors(), form_error(), in the view and controller. I've tried with and without custom messages, I've tried using a callback function instead, I've tried with and without square brackets in the name when I set the rules. I don't understand. I have a login form that works fine, I can't see what I've done. The problem form is loaded from this view: Code: <?=form_open(uri_string())?> And results quite happily in this: Code: <form action="http://localhost/permissions/edit/1" method="post"><fieldset> The controller function responsible is here: Code: function edit($group_id) Much obliged for your time! Form Validation Problem - El Forum - 09-24-2010 [eluser]sketchynix[/eluser] Code: function edit($group_id) You shouldnt be making database calls like this in the controller.. make a method in your model Code: //Firstly check that the group id exists. if you want to pm me the code, id be willing to rework it a bit. Form Validation Problem - El Forum - 09-25-2010 [eluser]Unknown[/eluser] Hi Sketchynix, thanks for helping out; [quote author="sketchynix" date="1285376709"] You shouldnt be making database calls like this in the controller.. make a method in your model [/quote] You're absolutely right; I hadn't even realised I'd put that call in the controller. Probably the caffeine dulling my brain. Apparently, this was also somehow hiding the error...Meh, I guess I'll chalk this one up to the "Learning Curve" column. Thanks for the offer of reworking, but I'll be ok, I like to do things by rapid prototyping! |