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-67b084e8f2ce6292970359/] Contact_form.php - view [crayon-67b084e8f2cf6432004643/] Contact_model [crayon-67b084e8f2cfd642242682/] Captcha Helper [crayon-67b084e8f2d04063429744/] Notifications_model [crayon-67b084e8f2d0c514418179/] Database…

6 years ago

Delete Files and Execute Database Query remotely

[crayon-67b084e8f30fe202929586/] [crayon-67b084e8f3104549504671/]  

6 years ago

Random String Codeigniter

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

6 years ago

Codeigniter Ajax Form Validation Example

Create Controller [crayon-67b084e8f3398801280249/] 2. Create View File [crayon-67b084e8f339f856431994/]  

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-67b084e8f35d9893924112/] application/model/Pagination_model.php [crayon-67b084e8f35df044928914/] application/controllers/Pagination.php [crayon-67b084e8f35e2002078169/] application/views/pagination.php [crayon-67b084e8f35e7502606058/]  

7 years ago