There is honestly a few way's todo this. CI Has a great form validation tool that has a function called set_value which allows you to present the previously typed data into it, but thats not the only way... One thing I find myself doing all the time is storing the user input as a array on the controller, and since I like to reuse my views, I simply tell the controller to pass any post data to that array and pass that array to the view. Then, the view will always look to see if the array has data in it for the specific field, if its there... put the contents into the value section... It's actually rather simple once you do it a few times...
Here's an example.
MyController.php
<?php
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
}
function index()
{
if($_SERVER['REQUEST_METHOD'] == "POST"){
//get the form data
$data['search_keyword'] = array(
"field1" => $this->input->post('field1'),
"field2" => $this->input->post('field2')
);
//load the database model
$this->load->model('my_model');
//pass the data to the database
$data['results'] = $this->my_model->search($data['search_keywords']);
//load the view with the results and form data
$this->load->view('search', $data);
} else {
$this->load->view('search');
}
}
}Then my view
<html>
<head>
<title>My View</title>
</head>
<body>
<form method="post" action="MyController/form">
<input type="text" name="field1" value="<?php if(!empty($search_keyword['field1'])){ echo $search_keyword['field1'];?>">
<input type="text" name="field2" value="<?php if(!empty($search_keyword['field2'])){ echo $search_keyword['field2'];?>">
</form>
</body>
</html>
Now I havent tested this stuff, but its basically what I do most of the time I am trying to accomplish what you are doing.
Even though this all works fine, CI has some great libraries for forms and validation and databases and I highly recommend spending the time looking into to leveraging those over just plain old php and html.
Let me know if that helps!
Thanks,
Peter