01-07-2010, 05:46 AM
[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.
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();
}
}