Question about form validation - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Question about form validation (/showthread.php?tid=42390) |
Question about form validation - El Forum - 06-06-2011 [eluser]bonjurkes[/eluser] Hello, I used a script that is premade with checkboxes for my own project. But at the source of the script that i found it required for form fields to get validated before submitted. So here comes the problem, i have like 61 checkboxes on my form, and writing like this : Code: $this->form_validation->set_rules('a60', 'a60', 'trim|max_length[255]'); will take so much time and wont look so nice in the code. My all formfield's id stars with "a", so is there a way to use something like "$a. $i" for setting rules for every field ? How can i do that ? Otherwise i have to type like a61, a60, a59 etc. Question about form validation - El Forum - 06-06-2011 [eluser]Twisted1919[/eluser] If you know for sure your number of checkboxes, do a for() loop, no problem with this. But i would use arrays so instead of <input name="a1" /><input name="a2" /> i would use <input name="a[]" />, then i wouldn't validate this array at all in the form_validation rules, instead, i would do it after the validation has passed, something like: Code: if($this->form_validation->run()) Question about form validation - El Forum - 06-06-2011 [eluser]plain jane[/eluser] For validating <input name="a[]" /> we have validation rule like: Code: $this->form_validation->set_rules('a[]', 'A', 'required'); Thanks, ci user |