Creating and using validation callbacks
Callbacks are used when you want to validate data in a way that may not be supported by the CodeIgniter's validation class. The benefit of using callbacks is that posted data can be easily validated by a custom function you define, and errors, if any, are passed into the error reporting functions.
How to do it...
We're going to amend the file:
/path/to/codeigniter/application/controllers/form.php
Amend that file to show the following:
$this->form_validation->set_rules('first_name', 'First Name', 'required|min_length[1]|max_length[125]'); $this->form_validation->set_rules('last_name', 'Last Name', 'required|min_length[1]|max_length[125]'); $this->form_validation->set_rules('email', 'Email', 'required|min_length[1]|max_length[255]|valid_email|callback_email_check'); ...
Get CodeIgniter 2 Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.