Welcome Guest, Not a member yet? Register   Sign In
Help with update profile page

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.
// 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);
            // Not logged in

Here is the code for the view (extra code snipped off, else it can't fit in this post):
// 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>';

I'm having some problems designing the profile update page. What I want it to do is:
- User opens the "Update Profile" page. It is populated with the data retrieved from the database.
- User updates the information and submits it.
- If there are any validation errors (using form_validation library), the same page is shown with the validation errors, and the form is filled with the UPDATED data that the user entered.
- This continues until the user enters valid data, which will be saved into the database, and the user will be redirected to a success page.

Right now it's not working. I can load the initial data from the database, but when I update it and submit, I'm brought back to the same page with the old data, and not the new data that I have updated.

By the way there is some problem with this forum. I took 10 minutes before I could successfully submit my post. Whenever I clicked Submit I kept getting redirected back to the New Topic page, and everything I typed in was deleted.

I tried to do an edit on my first post and the same thing happened - I kept getting redirected back to the edit page with my original text, even when I had updated it and submitted. That's why I decided to post a reply instead, which also took me 5 minutes before it finally went through.

What's going on?

It's been a week and no one has answered or even replied to my question? No wonder people are switching to Kohana... over here easy questions are answered quickly but when a real question pops up, no one knows how to help.

I'm sorry you feel that way. It is true that some questions are easier to answer than others. But also that some questions are asked more clearly than others. In your case, I have the feeling that you are combining techniques and that is causing problems:

You are using the validation library only partially and that doesn't work very well. The reason is that the validation library starts by reading from $_POST but then does its own handling of the information. So it could be that, when there are errors, you see your new values because they have been set by the validation library, but if everything goes well, you get the old values from the database because you are setting them by hand : $_POST = $result. My advice is to either do everything yourself, or use the validation library for everything.

Also, in your code I don't see anywhere that the data is being saved. Maybe you left it out, but it's hard for people to answer a very specific case if they have to guess about some aspects.

Theme © iAndrew 2016 - Forum software by © MyBB