Callbacks |
[eluser]aeternuslibertas[/eluser]
Hi How is everyone doing!? my question is with regard to callbacks... I was writing an application and wanted to check a user sign up for duplicate emails, just like this thread http://ellislab.com/forums/viewthread/168921/ my question is... how does the function, email_unique know to take the input value from the email field in the form into the parameter $str is it because of the Code: $this->form_validation->set_rules('email', 'Email', 'required|callback_email_unique'); Code: function email_unique($str) my approach looks something like this... Code: function email_unique() does it make a difference if i keep the Code: $str Code: $email=$this->input->post('email');
[eluser]CroNiX[/eluser]
It is doing the same thing internally. In the validation library it checks to see if a callback function exists. If it does, it passes the form value for that field as $str to the callback function. Likewise, if you wanted to add an additional parameter to your callback function, like they do with min_length[length] where length is passed, it will pass anything in brackets as the second parameter to your callback function so you can use it for additional checks. Since its already doing this for you, you might as well use the $str it is already passing. No need to do it a second time.
[eluser]aeternuslibertas[/eluser]
awesome thanks! before i stumbled upon how to correctly check for duplicate emails, i was using this code, that i wrote, and it wasn't working... i spent hours on it, can u see something that i was missing? Code: function check_duplicate_email($email){
[eluser]cideveloper[/eluser]
first of all there is no reason for you to pull the entire table and then loop through it. That is just bad practice. You should only select things you are looking for. Code: $this->db->select('email')->where('email', $email)->get('realtors',1); secondly your true/false will always return true unless the email address is the last email in the table. See example below loop 1 - $email!=$row->email - true loop 2 - $email!=$row->email - true loop 3 - $email==$row->email - false loop 4 - $email!=$row->email - true loop 5 - $email!=$row->email - true then you return the last. As you can see this will never work unless the email address is the last email in the table. loop 6 - $email!=$row->email - true
[eluser]Unknown[/eluser]
Excellent post. I want to thank you for this informative read and I appreciate you sharing. Keep up the good work. For your <a href="http://www.thenvs.com">car servicing Ascot</a> needs, please let me know. More power! |
Welcome Guest, Not a member yet? Register Sign In |