Welcome Guest, Not a member yet? Register   Sign In
How to update account when user don't want to update all database field
#2

Below is my Controller method for letting users update their details.

I am using ion_auth to update the details, but it's simply a Model wrapper.

PHP Code:
   public function index()
 
   {
 
       $this->form_validation->set_rules('username''Username''trim');
 
       $this->form_validation->set_rules('first_name''First name''required|trim');
 
       $this->form_validation->set_rules('last_name''Last name''required|trim');
 
       $this->form_validation->set_rules('telephone''Telephone''trim');
 
       $this->form_validation->set_rules('email''Email''required|trim|valid_email|callback_new_email_is_unique');
 
       $this->form_validation->set_rules('new_password''New password''trim|xss_clean|matches[confirm_new_password]');
 
       $this->form_validation->set_rules('confirm_new_password''Confirm new password''trim');

 
       $this->form_validation->set_rules('twitter_username''Twitter Username''trim');
 
       
        if 
($this->form_validation->run() == FALSE):
 
           
            $this
->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
 
           
            $this
->load->vars($this->data);
 
           $this->load->view('account/index');
 
       else:
 
           $data = array(
 
               'first_name' => $this->input->post('first_name'),
 
               'last_name' => $this->input->post('last_name'),
 
               'telephone' => $this->input->post('telephone'),
 
               'email' => $this->input->post('email'),
 
               'twitter_username' => $this->input->post('twitter_username')
 
           );
 
       
            if
($this->input->post('new_password') != '' && $this->input->post('confirm_new_password') != ''):
 
               $data['password'] = $this->input->post('new_password');
 
           endif;
 
       
            if
($this->ion_auth->update($this->user->id$data)):
 
               $this->session->set_flashdata('success-message''You have successfully updated your details.');
 
           else:
 
               $this->session->set_flashdata('error-message''Oops, something went wrong. Please try again.');
 
           endif;
 
           
            redirect
($this->session->flashdata('referrer'), 'location');
 
       endif;
 
   
Reply


Messages In This Thread
RE: How to update account when user don't want to update all database field - by mr_pablo - 01-04-2016, 09:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB