Replacing valid_email() with filter_var() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: Replacing valid_email() with filter_var() (/showthread.php?tid=65125) |
Replacing valid_email() with filter_var() - oz1cz - 05-03-2016 According to this description the valid_email() function is deprecated and scheduled for removal in CodeIgniter 3.1+. The web page says that the PHP function filter_var() should be used instead. But filter_var() takes two arguments, whereas valid_email() only takes one. So how do I specify a two-argument function with a fixed second argument in a form validation list? For example this example uses this code: Code: $this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]'); How can I replace valid_email here with filter_var with FILTER_VALIDATE_EMAIL as the second argument? Or am I supposed to write my own valid_email() function? -- Claus RE: Replacing valid_email() with filter_var() - InsiteFX - 05-03-2016 Yes you would need to write your own or use a callback: PHP Code: if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) { RE: Replacing valid_email() with filter_var() - oz1cz - 05-03-2016 Replying to my own question here: It appears that I've been confused about a few things: While the valid_email() function from the Email Helper is deprecated, the valid_email() function from the Form Validation Library is not. Obviously, I was just confused by the two functions having the same name, but one is located in the file system/helpers/email_helper.php, and the other is located in the file system/helpers/Form_validation.php. Sorry for the mixup. -- Claus RE: Replacing valid_email() with filter_var() - drusnac19 - 10-15-2016 (05-03-2016, 12:06 PM)InsiteFX Wrote: Yes you would need to write your own or use a callback: I would rather extend the CI_Form_Validation then write a callback. This is the best way to do this because you will have a new rule in all controllers and it's keep clean your controllers |