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

[eluser]Loquela[/eluser]
Hi there,

I am just loving Codeigniter by the way! I have never done OOP before and I am using this framework to learn all about it. Thank you very much!!

Below I have two functions, update_admin() which displays an update form and populates the fields with the content of the returned row. update_user() validates the user input and updates the selected record if validation is passed.

If validation fails then it reloads update_admin() - the update form with any validation errors.

This all works fine, I am returned to the form and validation messages appear as they should, but I get errors because the variable that contains the record to be updated is now empty. How can I reload update_admin() after a failed validation and return the record that I am trying to update?

I hope my question is clear. Any help much appreciated. Thanks.


Code:
// Display update user form
    function update_admin()
    {
        $data['title'] = 'Update admin user';
        $data['rows'] = $this->users_model->get_admin_users(); // get list of admin users
        $data['row'] = $this->users_model->get_user(); // 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()
    {    
        $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();
        }
        else
        {
        $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->users_model->update_user($data);
            $this->update_admin();
        }
    }


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