pengkong / A3M-for-CodeIgniter-2.0

A3M Peanutbutter - For CodeIgniter 2.0
Other
109 stars 84 forks source link

Form input still shows value after set to empty #7

Closed markstreich closed 11 years ago

markstreich commented 11 years ago

Hi,

I'm using A3M as my intro to CI. Thank you for the awesome platform to work with and learn from!

Here's a small issue. I think I understand what's happening but I'm not comfortable enough with the language to feel like I fixed it correctly.

If you have an account setting already with a value, first name as an example, and then change the value to empty, it updates the database but the input value on the resulting page will retain the old value. If you refresh the page, it is empty, but it appears to the user as if it wasn't updated.

This is because the account_settings view (line 46) checks set_value('settings_firstname') to determine if it should show the set_value, but after setting it to empty that variable is null, so it uses $account_details->firstname instead, which was queried before the database update.

This seems to work, but not sure if it's ideal:

'value' => $this->input->post() ? set_value('settings_firstname') : (isset($account_details->firstname) ? $account_details->firstname : ''),
pengkong commented 11 years ago

a really simple solution is to refresh the $account_detail object after the update. you can do this either by querying the database again or directly updating the object in php.

i.e. $data['account_detail']->firstname = $this->input->post('settings_firstname');

pengkong commented 11 years ago

your proposed solution doesnt really work right... if i set EVERY field to empty... then it will fail too haha. cuz' you're assuming something else wont be empty.

markstreich commented 11 years ago

Yeah I'm a newb to CI, I have no idea what the best solution is, but if you set every field blank it will error because email is required.