Model method for form validation |
[eluser]vertmonkee[/eluser]
When a user submits the registration form I want to check if the email address already exists in the database. I am trying to do it using a function in my pereson model. The person_model file looks like this Code: <?php The register controller looks like this Code: <?php Entering an email address that exists in the database or one that doesn't makes no difference the validation still allows the user to register. Is this the correct way of trying to implement this piece of validation?
[eluser]danmontgomery[/eluser]
Code: $rules['email'] = "required|valid_email|".$this->person_model->emailExists($this->input->post("email")); Is wrong... You don't pass the function result to the form_validation class, you pass the name of a callback function. I'm not aware of a way you can use a callback in a different class without extending the form_validation library, but someone else might. [edit] I suppose you could create a controller function which just returns the result of Person_model::emailExists(): Code: function callback_emailExists($str) { http://ellislab.com/codeigniter/user-gui...#callbacks
[eluser]vertmonkee[/eluser]
Thanks for that. I have implemented it by returning the person_model->emailExists Worked perfectly. |
Welcome Guest, Not a member yet? Register Sign In |