Form Validation Error |
[eluser]xtremer360[/eluser]
I'm working on my register form and I have it submitting via jQuery with having some validation checks client side and then of course on the server side but I get an error when I hit submit. When I submit the form I get this message: <b>Fatal error</b>: Call to private method Register::username_exists() from context 'CI_Form_validation' in <b>/home/xtremer/public_html/system/libraries/Form_validation.php</b> on line <b>593</b><br /> Code: $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric|strtolower|callback_username_exists'); Code: private function username_exists($str)
[eluser]CroNiX[/eluser]
callbacks need to be public or the validation class can't access them. If you want to make it "private" so it's not accessible via the URL, CI lets you prefix the method name with an underscore, and do the same when you are setting the rules. Code: public function _username_exists($str) Code: //2 underscores
[eluser]CroNiX[/eluser]
As a side note, you should put any validation rules that manipulate data (instead of "testing" it), such as strtolower, AFTER any other rules that return a TRUE/FALSE.
[eluser]xtremer360[/eluser]
Well I do already have validation rules set up. Does anything I'm doing in this controller look off? http://pastebin.com/wRKBRqdf
[eluser]xtremer360[/eluser]
Well that's just it I'm not quite understanding what your saying. Could you possibly rephrase it for me so I could understand. Thank you.
[eluser]CroNiX[/eluser]
You can't have a private function as a validation callback. The validation class can't access the private function defined as private in the controller, that's just php. You need to make it "private" with an underscore like the user guide states here: http://ellislab.com/codeigniter/user-gui...ml#private After doing that, you will have an extra underscore in the name of your callback function, which you then need to add to where you are setting the rules. I don't know how to make it much more clear. I think the first post was more clear. Sorry.
[eluser]xtremer360[/eluser]
If you look at the pastebin I had make them private.
[eluser]CroNiX[/eluser]
I did, and no, you didn't. I don't see any of your callback functions prefixed with underscores to make them private like I stated and the userguide I linked to explains. Code: public function is_username_available() Code: public function _is_username_available()// prefixed with "_" Code: $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric|strtolower|callback_username_exists'); Code: //extra underscore in 'callback__username' The same needs to be done for this function and also its rules Code: public function is_email_available()
|
Welcome Guest, Not a member yet? Register Sign In |