Welcome Guest, Not a member yet? Register   Sign In
call back function not working
#1

[eluser]Shiva666[/eluser]
I'm trying to create a call back function.
In the call back function it has to check if the email address is already in the database and if it is it must give a message saying its unique, but if a person edits their details there must not be any error messages regarding the email.



This is the call back function in my users controller
Code:
public function edit($id = NULL){
  $id == NULL || $data['user'] = $this->mdl_users->get($id);
  $rules = $this->mdl_users->rules_admin;
  $id || $rules['password']['rules'] .= '|required';
  $this->form_validation->set_rules($rules);
  if($this->form_validation->run() == TRUE){
  
  }

  $data['view_file'] = "edit";
  $this->load->module('templates');
  $this->templates->admin($data);
  
}

public function _unique_email($str){
  $id = $this->uri->segment(4);
  $this->db->where('email', $this->input->post('email'));
  !$id || $this->db->where('id !=', $id);
  $user = $this->mdl_users->get();
  
  if(count($user)){
   $this->form_validation->set_message('_unique_email', '%s should be unique');
   return FALSE;
  }
  
  return TRUE;
}

This is the rules in the users model. It's declared before the constructor
Code:
public $rules = array(
  'email' => array(
   'field' => 'email',
   'label' => 'Email',
   'rules' => 'trim|required|valid_email|xss_clean'
  ),
  
  'password' => array(
   'field' => 'password',
   'label' => 'Password',
   'rules' => 'trim|required'
  ),
);

public $rules_admin = array(
  'name' => array(
   'field' => 'name',
   'label' => 'Name',
   'rules' => 'trim|required|xss_clean'
  ),
  
  'email' => array(
   'field' => 'email',
   'label' => 'Email',
   'rules' => 'trim|required|valid_email|callback__unique_email|xss_clean'
  ),
  
  'password' => array(
   'field' => 'password',
   'label' => 'Password',
   'rules' => 'trim|matches[password_confirm]'
  ),
  
  'password_confirm' => array(
   'field' => 'password_confirm',
   'label' => 'Confirm password',
   'rules' => 'trim|matches[password]'
  ),
);




Theme © iAndrew 2016 - Forum software by © MyBB