![]() |
Validation library/Helper form - 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: Validation library/Helper form (/showthread.php?tid=12474) |
Validation library/Helper form - El Forum - 10-20-2008 [eluser]Mat-Moo[/eluser] I'm trying to do a contact form, and learning as I go ![]() Code: $rules['fname'] = "trim|required|min_length[5]|max_length[48]|xss_clean"; As you can see in $data[fname] I'm trying to set the class of the box depending on the bases of the validation (textbox) or (textbox error). But I can't work out how you validate, or check the validation of a single field? I'm doing it this way as my form uses the form_input($fname) rather than a basic html form. Clues and inputs aer welcome ![]() Validation library/Helper form - El Forum - 10-20-2008 [eluser]roj[/eluser] Just thinking off the top of my head, but a quick function to see if the error exists and return the error class if it does might work? Code: function return_error_class($err_msg) then just call it for each input you want to check? not sure if that' what your looking, nor if it'll work.... Validation library/Helper form - El Forum - 10-20-2008 [eluser]Mat-Moo[/eluser] Code: ($this->validation->fname_error<>"") ? 'textbox error' : 'textbox' Should be the same thing really. Validation library/Helper form - El Forum - 10-20-2008 [eluser]McNoggin[/eluser] I think you need to run the validation before it will generate the error messages. You need to call $this->validation->run() somewhere after this line $this->validation->set_fields($data); and before data["fname"] = array('name' => 'fname', 'id' => 'fname', 'class' => ($this->validation->fname_error<>"") ? 'textbox error' : 'textbox', 'value' => $this->validation->fname); Otherwise I don't think its generated the error message yet. Validation library/Helper form - El Forum - 10-20-2008 [eluser]Mat-Moo[/eluser] Thanks - but that is called before data["fname"] (Line before infact) Validation library/Helper form - El Forum - 10-20-2008 [eluser]roj[/eluser] Sorry reading this on phone just isn't as good as on a computer... you should be setting the form_helper data after the validation is run ie something like this: Code: $rules['fname'] = "trim|required|min_length[5]|max_length[48]|xss_clean"; Validation library/Helper form - El Forum - 10-21-2008 [eluser]Mat-Moo[/eluser] Sometimes you can stare so hard at these things that you miss them ![]() |