I use one view for adding/editing DB data:
<input name="blah" id="blah" value="<? set_selected('blah')?> />
In my controller for edit I do this:
$_POST['blah'] = 'DB value';
$this->load->view('...');
But the input field is blank. I want the inputs to be prepopulated for my edit case.
CI Views can take a data array as the second parameter as others have mentioned.
http://codeigniter.com/user_guide/general/views.html
I don’t like the idea of setting the $_POST array and then passing that as your data array. $_POST should just be used for values passed from the UI form. Since you would have to manually set your $_POST array anyways, you might as well use a separate array object. I would create an array with all your set values. i.e. array(‘blah’ => $dbvalue); and pass that instead of a pre-populated $_POST array.
Secondly, your example code uses ‘set_selected()’. The function is ‘set_select()’ and is meant for a option tag. So there are two issues with that line of code. It needs to either be
or