10-08-2009, 06:10 AM
[eluser]mattpointblank[/eluser]
If I'm editing pre-populated values using the form_validation class, I do something like this:
This way, on first load, my page will show the database information, but if I modify it and submit the form again, it remembers my new value that was POSTed.
When I'm producing big, complex forms, I cheat a little and use the same form view to add and edit data. I use the above method, but add an @ sign in front of $stuff['something'] which means that in my controller, the edit() method can define $data['stuff'], but the add() one doesn't, and the error message is suppressed. It's a little hacky but it means that if I need to change my form, I don't have to modify it in two places (which gets complicated).
If I'm editing pre-populated values using the form_validation class, I do something like this:
Code:
$data['stuff'] = $this->Some_model->getStuff();
// then in my form view:
<input type="text" name="something" value="<?php echo set_value('something', $stuff['something']); ?>" />
This way, on first load, my page will show the database information, but if I modify it and submit the form again, it remembers my new value that was POSTed.
When I'm producing big, complex forms, I cheat a little and use the same form view to add and edit data. I use the above method, but add an @ sign in front of $stuff['something'] which means that in my controller, the edit() method can define $data['stuff'], but the add() one doesn't, and the error message is suppressed. It's a little hacky but it means that if I need to change my form, I don't have to modify it in two places (which gets complicated).