Custom validation method - Issue with error message. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Custom validation method - Issue with error message. (/showthread.php?tid=65335) |
Custom validation method - Issue with error message. - happyape - 05-31-2016 Code: class Form extends CI_Controller { The above validation fails with this error message Code: "Unable to access an error message corresponding to your field name" I tried to search on SO and this one seem to be the exact issue I am having - http://stackoverflow.com/questions/32665715/codeigniter-unable-to-access-an-error-message-corresponding-to-your-field-name The OP was able to resolve this issue (see his own answer) Code: 1. Create MY_Form_validation.php file in libraries folder and paste following code in it. But still didn't resolve the issue for me. What do I do? RE: Custom validation method - Issue with error message. - Avenirer - 05-31-2016 I guess you must load the form validation library inside that callback method (username_check...) too. You are calling form_validation but you didn't load the library. RE: Custom validation method - Issue with error message. - happyape - 05-31-2016 Hello - Actually I have loaded the form validation library in the constructor. The above code was just copied & pasted from the CI documentation as my code was very identical except as mentioned below. http://www.codeigniter.com/userguide3/libraries/form_validation.html?highlight=validation#callbacks-your-own-validation-methods This rule in the example above works fine so I was wrong to say it doesn't work. I had used an additional rule "email" which was a typo as it should have been "valid_email" and that was causing this error for me. This is what I had in my rules list. Code: $this->form_validation->set_rules('username', 'Username', 'email|callback_username_check'); So basically, everything works well. My typo created the problem for me. Please close my thread. Thank you. |