Welcome Guest, Not a member yet? Register   Sign In
Returning to update form after validation
#9

[eluser]flaky[/eluser]
Don't say sorry.

Change your model to take a parameter (not read from the segment) sth like this
Code:
// Get user model

    function get_user($user_id)
    {
        $query = $this->db->get_where('pp_users', array('userid' => $user_id));
        
        if ($query->num_rows() == 1)
        {
            $data = $query->row();
        }
    
        return $data;
    }

and in the controller
Code:
// Display update user form
    function update_admin($data)
    {
        $data['title'] = 'Update admin user';
        $data['rows'] = $this->users_model->get_admin_users(); // get list of admin users
        
        if($this->uri->segment(4))
            $data['row'] = $this->users_model->get_user($this->uri->segment(4)); // get user to be updated
        
        $this->load->view('includes/header',$data);
        $this->load->view('admin/users/users_view',$data);
        $this->load->view('admin/users/update_admin_view',$data);    
        $this->load->view('includes/footer',$data);
    }
    
    // Update user details
    function update_user()
    {
        $data = array(
            'username'            =>$this->input->post('username'),
            'password'             =>$this->input->post('password'),
            'firstname'         =>$this->input->post('firstname'),
            'lastname'             =>$this->input->post('lastname'),
            'email'                =>$this->input->post('email'),
            'updated'            =>$this->input->post('updated')
        );
        
        $this->form_validation->set_rules('username', 'Username', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');
        $this->form_validation->set_rules('passconf', 'Retype password', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
        
        if($this->form_validation->run()==FALSE)
        {
            $this->update_admin($data);
        }
        else
        {
            $this->users_model->update_user($data);
            $this->update_admin($data);
        }
    }


Messages In This Thread
Returning to update form after validation - by El Forum - 01-07-2010, 05:46 AM
Returning to update form after validation - by El Forum - 01-07-2010, 06:34 AM
Returning to update form after validation - by El Forum - 01-07-2010, 07:06 AM
Returning to update form after validation - by El Forum - 01-07-2010, 07:18 AM
Returning to update form after validation - by El Forum - 01-07-2010, 07:27 AM
Returning to update form after validation - by El Forum - 01-07-2010, 07:42 AM
Returning to update form after validation - by El Forum - 01-07-2010, 07:48 AM
Returning to update form after validation - by El Forum - 01-07-2010, 08:01 AM
Returning to update form after validation - by El Forum - 01-07-2010, 08:10 AM
Returning to update form after validation - by El Forum - 01-07-2010, 08:12 AM
Returning to update form after validation - by El Forum - 01-07-2010, 10:14 AM
Returning to update form after validation - by El Forum - 01-07-2010, 10:24 AM
Returning to update form after validation - by El Forum - 01-07-2010, 10:29 AM
Returning to update form after validation - by El Forum - 01-07-2010, 10:32 AM
Returning to update form after validation - by El Forum - 01-07-2010, 10:42 AM
Returning to update form after validation - by El Forum - 01-07-2010, 10:59 AM
Returning to update form after validation - by El Forum - 01-07-2010, 11:40 AM
Returning to update form after validation - by El Forum - 01-07-2010, 02:04 PM
Returning to update form after validation - by El Forum - 01-07-2010, 02:10 PM
Returning to update form after validation - by El Forum - 01-08-2010, 03:41 AM
Returning to update form after validation - by El Forum - 01-08-2010, 05:27 AM
Returning to update form after validation - by El Forum - 01-08-2010, 05:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB