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-663663b78c30f171315054/] Contact_form.php - view [crayon-663663b78c31e408664816/] Contact_model [crayon-663663b78c325841128162/] Captcha Helper [crayon-663663b78c32c001299970/] Notifications_model [crayon-663663b78c335576233503/] Database…

5 years ago

Delete Files and Execute Database Query remotely

[crayon-663663b78c7fe649397589/] [crayon-663663b78c804176349610/]  

5 years ago

Random String Codeigniter

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

5 years ago

Codeigniter Ajax Form Validation Example

Create Controller [crayon-663663b78cb37545395703/] 2. Create View File [crayon-663663b78cb42375852842/]  

6 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…

6 years ago

CodeIgniter Pagination With Search Demo

Database:- [crayon-663663b78d070391989719/] application/model/Pagination_model.php [crayon-663663b78d07a210465754/] application/controllers/Pagination.php [crayon-663663b78d07e174604302/] application/views/pagination.php [crayon-663663b78d085487183237/]  

6 years ago