Welcome Guest, Not a member yet? Register   Sign In
form field not updating
#10

[eluser]TheFuzzy0ne[/eluser]
That's right, but some people will manipulate the URL to intentionally break your app, or find weaknesses and/or exploits. The reason I asked is because I was going to have a bash at restructuring your method.

As I mentioned before, I see no immediate reason why what you've got shouldn't work, based on the fact that the rest seems to work. What could be responsible for this? The weather? Fluctuations in the stock market? I have a hunch that it's the code that's the problem, since you're doing a lot of checks that serve no real purpose. If you structure your code a bit better, it will be more robust, and a heck of a lot easier to debug.

This code is untested, but it's cleaner, more robust, easier to follow and debug, less code than before and there's not a nested if-statement in sight.
Code:
function edit($account_id = '', $platform = '')
{
    // Check that the account exists. You can pull the default form field values for your views from here.
    if ( ! $data['account'] = $this->dashboard_model->get_account($account_id, $platform)) { // This is where you should validate the account_id and platform.
        show_error('Sorry, but we were unable to locate the requested account!');
    }
    
    // If we've got this far, we have an account.
    $data['account_id']    = '';
    $data['platform']    = '';
    $data['name']     = '';
    $data['location_city']   = '';
    $data['location_country'] = '';
    $data['status']    = '';
    $data['region']    = '';
    $data['link']    = '';
    $data['type']    = '';

    // Set validation rules.
    $this->form_validation->set_rules('account_id', 'Account ID', 'trim|required');
    $this->form_validation->set_rules('platform', 'Platform', 'trim|required');
    $this->form_validation->set_rules('name', 'Name', 'trim|required');
    $this->form_validation->set_rules('status', 'Status', 'trim|required');
    $this->form_validation->set_rules('location_city', 'City', 'required');
    $this->form_validation->set_rules('location_country', 'Country', 'required');
    $this->form_validation->set_rules('region', 'Region', 'required');
    $this->form_validation->set_rules('link', 'Link', 'trim|required');
    $this->form_validation->set_rules('type', 'Type', 'trim|required');
    
    // Make sure validation passes, and
    if($this->form_validation->run() AND $this->dashboard_model->update_account()) {
        // Here, I'd normally set a flash message redirect back to the view method.
        $data['message'] = ' - Update complete!';
    }
    
    // Load the view.
    $this->load->view('manage/edit', $data);
}

I'd be interested to know if it makes any difference. It might not but it should be much easier to debug.

show_error() isn't necessarily the best way to handle this, but it's better than showing a blank page, no?

It's entirely up to you whether or not you accept my help. I leave it to you.


Messages In This Thread
form field not updating - by El Forum - 03-29-2013, 09:06 AM
form field not updating - by El Forum - 03-29-2013, 09:43 AM
form field not updating - by El Forum - 03-29-2013, 09:53 AM
form field not updating - by El Forum - 03-29-2013, 10:11 AM
form field not updating - by El Forum - 03-29-2013, 10:25 AM
form field not updating - by El Forum - 03-29-2013, 10:54 AM
form field not updating - by El Forum - 03-29-2013, 10:59 AM
form field not updating - by El Forum - 03-29-2013, 11:12 AM
form field not updating - by El Forum - 03-29-2013, 11:25 AM
form field not updating - by El Forum - 03-29-2013, 12:12 PM
form field not updating - by El Forum - 04-01-2013, 05:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB