Need help with the new form validation - El Forum - 02-20-2009
[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');
}
Need help with the new form validation - El Forum - 02-20-2009
[eluser]Unknown[/eluser]
This is the view
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="<?=base_url();?>public/css/initial.css" rel="stylesheet" type="text/css" />
<title>Element Admin</title>
</head>
<body>
<div id="background">
<div align="center">
<div id="wrapper">
<div id="header_area">
<?php include_once "include/header.php"; ?>
</div>
<div id="hrz_menu_area">
<div class="top_header_left">
</div>
<div class="top_header_middle">
<?php include_once "include/hrz_menu.php"; ?>
</div>
<div class="top_header_right">
</div>
</div>
<div id="quick_link_area">
<div class="grey_header_left">
</div>
<div class="grey_header_middle">
<?=$quick_link;?>
</div>
<div class="grey_header_right">
</div>
</div>
<div id="content_area" align="left" style="line-height:15px;">
<?php echo validation_errors(); ?>
<?php echo $error;?>
<?php echo form_open_multipart('administrator/product/add'); ?>
<h3>Product Category</h3>
<select name="category">
<option value="" >Pilih Category</option>
<option value="Piano" <?php echo set_select('category', 'Piano'); ?> >Piano</option>
<option value="String" <?php echo set_select('category', 'String'); ?> >String</option>
<option value="Wind" <?php echo set_select('category', 'Wind'); ?> >Wind</option>
<option value="Percussion" <?php echo set_select('category', 'three'); ?> >Three</option>
<option value="Accessories" <?php echo set_select('category', 'Accessories'); ?> >Accessories</option>
<option value="Others" <?php echo set_select('category', 'Others'); ?> >Others</option>
</select>
<h3>Product Name</h3>
<input type="text" name="name" value="<?php echo set_value('name'); ?>" size="50" />
<h3>Product Description</h3>
<textarea name="description" cols="" rows="" style="width:50%; height:100px;"><?php echo set_value('description'); ?></textarea>
<h3>Product Image</h3>
<input type="file" name="userfile" size="50" />
<div><br /><input type="submit" value="Submit" /></div>
</form>
</div>
<div id="footer_area">
<div class="footer_bg_left">
</div>
<div class="footer_bg_middle">
<?php include_once "include/footer.php"; ?>
</div>
<div class="footer_bg_right">
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Need help with the new form validation - El Forum - 02-20-2009
[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter community!
set_value() accepts a second parameter which will be used as the default when the $_POST array is empty.
|