[eluser]Celyst[/eluser]
I'm having some problems designing the profile update page. What I want is for the page to load up with the current profile data (taken from the database). The user can then update their profile data, and submit it to the database. It will be verified using the form_validation library, then written to the database.
This is the code in my controller. It loads the model, which queries the database for the profile information, and passes it on to the view.
Code:
// Update profile information
function edit_profile()
{
// Check session
if ($this->session->userdata('logged_in'))
{
// Load model
$this->load->model('Member_info', '', TRUE);
// Get initial data from DB and put it in $_POST
$result = $this->Member_info->get_profile_info($this->session->userdata('email'));
$result = $this->Member_info->make_profile_data_updatable($result);
$_POST = $result;
$data['title'] = "Update Profile";
$data['heading'] = "Update Profile";
$this->load->view('header', $data);
$this->load->view('members/update');
$this->load->view('footer');
}
else
{
// Not logged in
redirect('/login');
}
}
Here is the code for the view (extra code snipped off, else it can't fit in this post):
Code:
<?php
// Create arrays to store the attributes for the form elements
$form_action = "members/profile/edit";
$form_attributes = array('id' => 'reg_form');
$data['firstname'] = array('name' => 'firstname', 'id' => 'firstname', 'value' => set_value('firstname'));
$data['lastname'] = array('name' => 'lastname', 'id' => 'lastname', 'value' => set_value('lastname'));
$options['gender'] = array('' => '', '1' => 'Male', '2' => 'Female');
// Validation errors echoed here
echo validation_errors();
// Construct form HTML using attribute arrays
echo form_open($form_action, $form_attributes);
echo '<p>';
echo form_label('First Name: ', 'firstname');
echo form_input($data['firstname']);
echo '<p /><p>';
echo form_label('Last Name: ', 'lastname');
echo form_input($data['lastname']);
echo '<p /><p>';
echo form_label('Gender: ', 'gender');
echo '<select name="gender" id="gender">';
foreach ($options['gender'] as $key => $value)
{
echo "<option value=$key ";
echo set_select('gender', $key);
echo '>' . $value . '</option>';
}
echo '</select>';