[eluser]Unknown[/eluser]
Hi need help with populated form when getting data from database using the new form validation in CI 1.7.1 ...
This is the code in the controller ...
Code:
$query = $this->product->_get_product_detail_by_id($id);
if ($query->num_rows() >=1 )
{
$row = $query->row();
$data['quick_link'] = '<div class="full_area" style="line-height:33px;" align="left">
<span style="color:grey;"><b>Quick Links :</b></span><span style="color:#8ab00f;"><b> <a href="'.base_url().'index.php/administrator/product/add">Add Product</a></b></span></div>';
$this->load->library('form_validation');
$this->form_validation->set_rules('category', 'Product Category', 'trim|required|xss_clean');
$this->form_validation->set_rules('name', 'Product Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('description', 'Product Description', 'trim|required|xss_clean');
$config['upload_path'] = './tmp/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ($this->form_validation->run() == FALSE || !$this->upload->do_upload())
{
$data['error'] = $this->upload->display_errors();
//How to Pass the data from database to the form view
$this->load->view('backend/product_detail', $data);
}
else
{
$category = $this->input->post('category', TRUE);
$name = $this->input->post('name', TRUE);
$description = $this->input->post('description', TRUE);
$upload = $this->upload->data();
$ext = $upload['image_type'];
$thumbs = './public/images/product/'.$upload['raw_name'].'.jpg';
$this->cropImage('250', '250', $upload['full_path'], $ext, $thumbs);
unlink($upload['full_path']);
$file_path = 'public/images/product/'.$upload['raw_name'].'.jpg';
// insert input data into database
$data_input = array (
'product_category' => $category,
'product_name' => $name,
'product_description' => $description,
'product_avatar' => $file_path
);
$this->product->_update_product_detail($id, $data_input);
$this->load->view('backend/success', $data);
}
}else{
redirect('','location');
}