![]() |
Form validation and error messages - 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: Form validation and error messages (/showthread.php?tid=4723) |
Form validation and error messages - El Forum - 12-12-2007 [eluser]AtlantixMedia[/eluser] Hello, I'm not clear on how CI validation works yet. Meaning...is there a way to return an error msg based on the actual error which occured? for example: $rules['username'] = "required|min_length[3]|max_length[15]"; $this->validation->set_rules($rules); etc if the input passes all but the min_length test, does the system say that? ideally, I would like to be able to return a personalized msg based on each error. I guess I will have to write this from scratch. someone please confirm this. thanks you Form validation and error messages - El Forum - 12-12-2007 [eluser]gtech[/eluser] have you followed through all the examples in the validation documentation as the answers to your questions are in there. yes the min_length will actually say that.. "The %s field must be at least %s characters in length."; NOTE: you can set the custom error message Code: $this->validation->set_message('required', 'Error %s is required honest guv'); if you use set_fields Code: $fields['username'] = 'Username'; Error Password Confirmations is required honest guv. instead of Error passconf is required honest guv. also have a look in system\language\english\validation_lang.php this is where the default error messages are stored. Form validation and error messages - El Forum - 12-12-2007 [eluser]LuckyFella73[/eluser] Hi, as far as I know there is no implemented way of checking which part of your rule-segments didn't match. What you can do is to personalize the error messages in general (for each rule). have a look at gtech's example (posted while I was writing this post ![]() Form validation and error messages - El Forum - 12-12-2007 [eluser]gtech[/eluser] also might me worth reading the "showing errors individually" section of the validation documentation. Form validation and error messages - El Forum - 12-12-2007 [eluser]AtlantixMedia[/eluser] thanks everybody for the heads up. basically, I intend to pass multiple rules, starting to test the most strict one. for example, required|min_length[3]|max_length[8] I test whether the input is null 1) if it is no more tests are done and a msg like 'sorry this field is required' is sent back. 2) if it's not, input is tested for min_lenght and so on until either it fails or passes all tests. also, I would have to test a few rules which are not built in CI. can this be implemented using CI validation library as is? thanks Form validation and error messages - El Forum - 12-12-2007 [eluser]gtech[/eluser] [quote author="AtlantixMedia" date="1197504563"]thanks everybody for the heads up. basically, I intend to pass multiple rules, starting to test the most strict one. for example, required|min_length[3]|max_length[8] I test whether the input is null 1) if it is no more tests are done and a msg like 'sorry this field is required' is sent back. 2) if it's not, input is tested for min_lenght and so on until either it fails or passes all tests. [/quote] yep thats what happens I believe. Quote:also, I would have to test a few rules which are not built in CI. yes read the documentation e.g. the bit that says "Callbacks: Your own Validation Functions" sometimes the best thing to do is give it a go, cut and paste the examples.. test what happens and then if you get problems ask on the forum ![]() Link to [url="http://ellislab.com/codeigniter/user-guide/libraries/validation.html"][Validation Docs][/url] |