Validation problem - Config | Callback | Controller |
[eluser]Multisnet[/eluser]
I need some help please.. I'm dealing with validation. After read the User Guide topic I decided to create a config file with rules for validation. form_validation.php example: Code: $config = array( in the controller I use Code: if ($this->form_validation->run('registoPaciente') == FALSE) The problem is in the callback verificaEmail. In the controller I implemented this method for test Code: function verificaEmail($str) When I run the application the Test message is displayed, however it return this error for the email field: Unable to access an error message corresponding to your field name. Could you help me? PS:Some expressions are in Portuguese but I think that I translated everything relevant. Thanks in advance
[eluser]TheFuzzy0ne[/eluser]
Try replacing this line: Code: $this->form_validation->set_message('email_existente', 'Error in e-mail'); with this: Code: $this->form_validation->set_message('verificaEmail', 'Error in e-mail'); The first parameter of the set_message method needs to be the name of your validation method.
[eluser]Multisnet[/eluser]
I will use this topic to another doubt, if I extend form validation class is it possible to create my own validation rules without callback? I would like to make some generic rules like (integer < x).
[eluser]TheFuzzy0ne[/eluser]
Yes, if the rule isn't prefixed with callback_, then the validation class is one of the first places the form validation library looks for the rule. You should also be able to create your own help function, and use that.
[eluser]Multisnet[/eluser]
My idea is to extend default CI form validation class, so i follow the user guide instructions: Quote:class MO_Form_Validation extends CI_Form_Validation { The extended class is loaded, however, my forms doesn't display errors anymore, It seems that the new class doesn't really extend the base CI class. I'm doing anything wrong?
[eluser]TheFuzzy0ne[/eluser]
I know this sounds like a silly question, but I just want to be sure - Have you changed the prefix from 'MY_' to 'MO_' in the config.php? Note the trailing underscore is very important.
[eluser]Multisnet[/eluser]
Yes I changed the prefix. I extended many other classes without any problem, I'm using MO_Controller perfectly. Code: class MO_Controller extends Controller { I realize now that the functions from form_validation don't work correctly (e.g. set_select() prints selected in every option). I can't understand the problem.
[eluser]pistolPete[/eluser]
This might be a capitalization issue: What's the filename? It should be MO_Form_validation.php. |
Welcome Guest, Not a member yet? Register Sign In |