Categories: Snippets

Codeigniter passing 2 arguments to callback – Email validation

$id = 2;
$this->load->library('form_validation');
        if ($this->input->server('REQUEST_METHOD') == 'POST') {
            $this->form_validation->set_rules('user_email', 'Email', 'min_length[5]|valid_email|required|xss_clean|callback_is_unique_email['.$id.']',array('required'=> 'You have not provided %s.','is_unique'=> 'This %s already exists.'));
            $this->form_validation->set_message('is_unique_email', 'Email Address already in use');
            $this->form_validation->set_message('valid_email', 'Please enter valid email address');
if ($this->form_validation->run() == FALSE) {
echo 'error';
} else {
echo 'success';
}
}
function is_unique_email($email, $id) {
        $this->db->where('user_email', $email);
        $this->db->where('id !=', $id);
        $query = $this->db->get('users');
        if($query->num_rows() > 0) {
            return false;
        } else {
            return true;
        }
    }

 

Recent Posts

Sample Contact Form with validation, Captcha & Notification

Contact Controller [crayon-68b74938a7cc5338057126/] Contact_form.php - view [crayon-68b74938a7cd7074075385/] Contact_model [crayon-68b74938a7cdf766926872/] Captcha Helper [crayon-68b74938a7ce9485967862/] Notifications_model [crayon-68b74938a7cf5251467239/] Database…

7 years ago

Delete Files and Execute Database Query remotely

[crayon-68b74938a80f0562618678/] [crayon-68b74938a80f8544108608/]  

7 years ago

Random String Codeigniter

[crayon-68b74938a835b473159803/] The first parameter specifies the type of string, the second parameter specifies the length.…

7 years ago

Codeigniter Ajax Form Validation Example

Create Controller [crayon-68b74938a8811572584534/] 2. Create View File [crayon-68b74938a8819464042500/]  

7 years ago

Setting Error Messages

All of the native error messages are located in the following language file: system/language/english/form_validation_lang.php To set…

7 years ago

CodeIgniter Pagination With Search Demo

Database:- [crayon-68b74938a9bfb794471441/] application/model/Pagination_model.php [crayon-68b74938a9c05364632474/] application/controllers/Pagination.php [crayon-68b74938a9c08977195802/] application/views/pagination.php [crayon-68b74938a9c0d817768432/]  

7 years ago