Replacing valid_email() with filter_var() |
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
Yes you would need to write your own or use a callback:
PHP Code: if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) { What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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 (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 |
Welcome Guest, Not a member yet? Register Sign In |