I am building a site where the user can become a member and have a minimal profile. Nevertheless, in the case that this user wishes to update his records (About Me, Email, Phone Number,etc), I want to have a link "Edit Profile". Once clicked a form is loaded with input fields with values populated from database record of that user. He/she can change the values in the fields and click Save Changes, then those are committed to database.
I tried doing it several times but kept failing. Below is the code I tried to load data in form:
public function load_edit()
{
//check user logged in
if(($this->session->userdata('username')!=""))
{
$data;
$result = $this->profileModel->load_user_editable_data($this->session->userdata('username'));
//check user data loaded successfully
if(isset($result))
{
//get the user information and store to $data array
foreach($result as &$value)
{
$data = $value;
}
$this->load->view('profile_edit', $data);
}
}else{
$this->login();
}
}
And to update record in database table:
public function update_edit()
{
$this->form_validation->set_rules('fullname', 'الاسم الكامل', 'isset|required|alpha_dash');
if(isset($_POST))
{
//check user logged in
if(($this->session->userdata('username')!=""))
{
//check that there are no form validation errors
if($this->form_validation->run() == FALSE)
{
$data = $this->profileModel->load_user_editable_data($this->session->userdata('username'));
$this->load->view('profile_edit', $data);
}else{
$result = $this->profileModel->update_profile($this->session->userdata('username'));
if($result){
$this->load->view('profile_edit', $result);
}
}
}
}else{
$this->load->view('error');
}
}
The main problem I faced with the execution of above code, is that somehow when I execute update_edit, it always tells me that form validation failed and even though the condition of the field is met.
Thanks for help in advance :)