Here's how I do it.
In the view file:
PHP Code:
<input type="text" id="price" name="product[price]" value="<?= set_value('product[price]') ?>"/>
I always use arrays for my form values, and I send the array to the form inside the $data array when loading the view. Something like this in my product controller file:
PHP Code:
public function add_product()
{
$message = 'Enter product and click Submit button';
$product = array(
'name' => '',
'price' => 0,
'description' => ''
);
// $this->form_validation->set_rules goes here
if ($this->form_validation->run())
{
$product = $this->input->post('product');
$data = array (
'name' => $product['name'],
'price' => $product['price'],
'description' => $product['description']
);
$this->products_model->add($data);
$message = 'Success! Enter another if you wish';
}
else
{
if (validation_errors())
{
$message = validation_errors();
$product = $this->input->post('product');
}
}
$data = array (
'message' => $message,
'product' => $product
);
$this->load->view('add_product_view', $data);
}
This way, the same view is used to both enter products and confirm success. The view shows the $message variable, which as you can see, can contain three different messages. The product array is first blank/zeros for the first time the form loads. After that, whether there's an error or not, it will contain what the user entered in the form.
The above is very stripped down, but let me know if it doesn't make sense.