[eluser]Matalina[/eluser]
I can't get the extended library to run. I've indicated the exit() that isn't working in the function. A second set of eyes would be helpful.
Controller:
Code:
public function profile() {
// Is the user logged in?
if(!$this->ion_auth->logged_in()) {
$this->session->set_flashdata('warning','<div class="alert-box warning">You must be logged in.</div>');
redirect('site/index');
}
// Get users information
$user = $this->ion_auth->user()->row_array();
if($this->input->post('update')) {
$this->form_validation->set_rules('email','valid_email|unique_email');
$this->form_validation->set_rules('password','xss_clean');
$this->form_validation->set_rules('confirm','xss_clean|match[password]');
$this->form_validation->set_message('unique_email','Email already in use');
if($this->form_validation->run() && ($this->input->post('email') OR $this->input->post('password'))) {
$id = $this->session->userdata('user_id');
if($this->input->post('email')) {
$info['email'] = $this->input->post('email');
}
if($this->input->post('password')) {
$info['password'] = $this->input->post('password');
}
$check = $this->ion_auth->update($id,$info);
if($check) {
$this->session->set_flashdata('success','<div class="alert-box success">User has been updated.</div>');
redirect('site/profile');
}
else {
$this->session->set_flashdata('error','<div class="alert-box error">User has not been updated.</div>');
redirect('site/profile');
}
}
}
// set data & display page
$data['user'] = $user;
$data['title'] = 'My Profile';
$this->template->load('templates/main_template','user/profile',$data);
}
/application/libraries/MY_Form_validation
Code:
function unique_email($email) {
echo '<pre>'; print_r($email); echo '<pre/>'; exit(); // <-- not working
$this->CI->load->model('User_model');
$this->CI->load->model('Stores_model');
if($this->CI->input->post('user_id')) {
$user_id = $this->CI->input->post('user_id');
}
else if($this->CI->input->post('create')){
$user_id = 0;
}
else {
$user_id = $this->CI->session->userdata('user_id');
}
$user_query = $this->CI->User_model->get(array('id' => $user_id));
if($user->num_rows() > 0) {
$user = $user_query->row_array();
}
else {
$user = false;
}
$email_query = $this->CI->User_model->get(array('email' => $email));
if($email_query->num_rows() > 0) {
if($email_query->row()->id == $user['id']) {
$this->CI->form_validation->set_message('unique_email','You are already using this email address');
return FALSE0;
}
else {
$this->CI->form_validation->set_message('unique_email','Someone has this email address already');
return FALSE;
}
}
$store_query = $this->CI->Stores_model->get(array('email' => $email));
if($store_query->num_rows() > 0) {
$this->CI->form_validation->set_message('unique_email','You may not use a store email address');
return FALSE;
}
return TRUE;
}