Why wouldn't you just set the value of the field to object->fieldname. Then load up the object, set the fields, and attempt a save. If the save fails, use the update object to prefill the form.
If the save succeeds, you don't need to do anything else.
Something like this:
Code:
function edit($id = 0) {
$w = new Widget();
// attempt to save the changes
if($this->input->post('id') !== FALSE) {
$w->get_by_id($this->input->post('id'));
$w->name = $this->input->post('name');
...
if($w->save) {
redirect('saved');
}
} else {
$w->get_by_id($id);
}
$this->load->view('widget_edit', array('widget' => $w));
}
Then in your view, output both the object and any errors that exist ($widget->error->{$fieldname}). This way, if someone types in a change, but makes a mistake, the changed value is passed back to the browser.
You should never reset an incorrect form to the original values. That's just bad programming! :-)
FYI: I won't be able to provide much feedback until next week, so questions may go unanswered.
Also, for BaRzO, I'm sorry, but you need to read the documentation, look through the rich history of examples, etc. I highly doubt anyone is going to write your app for you.