Welcome Guest, Not a member yet? Register   Sign In
Need help with the new form validation
#1

[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');
        }
#2

[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">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;link href="&lt;?=base_url();?&gt;public/css/initial.css" rel="stylesheet" type="text/css" /&gt;
&lt;title&gt;Element Admin&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<div id="background">
    <div align="center">
        <div id="wrapper">
            <div id="header_area">                
                &lt;?php include_once "include/header.php"; ?&gt;
            </div>
            <div id="hrz_menu_area">
                <div class="top_header_left">
                </div>
                <div class="top_header_middle">
                    &lt;?php include_once "include/hrz_menu.php"; ?&gt;
                </div>
                <div class="top_header_right">
                </div>
            </div>
            <div id="quick_link_area">
                <div class="grey_header_left">
                </div>
                <div class="grey_header_middle">
                    &lt;?=$quick_link;?&gt;
                </div>
                <div class="grey_header_right">
                </div>
            </div>
            <div id="content_area" align="left" style="line-height:15px;">
                &lt;?php echo validation_errors(); ?&gt;
                
                &lt;?php echo $error;?&gt;

                &lt;?php echo form_open_multipart('administrator/product/add'); ?&gt;
                
                <h3>Product Category</h3>
                <select name="category">
                <option value="" >Pilih Category</option>
                <option value="Piano" &lt;?php echo set_select('category', 'Piano'); ?&gt; >Piano</option>
                <option value="String" &lt;?php echo set_select('category', 'String'); ?&gt; >String</option>
                <option value="Wind" &lt;?php echo set_select('category', 'Wind'); ?&gt; >Wind</option>
                <option value="Percussion" &lt;?php echo set_select('category', 'three'); ?&gt; >Three</option>
                <option value="Accessories" &lt;?php echo set_select('category', 'Accessories'); ?&gt; >Accessories</option>
                <option value="Others" &lt;?php echo set_select('category', 'Others'); ?&gt; >Others</option>
                </select>
                
                <h3>Product Name</h3>
                &lt;input type="text" name="name" value="&lt;?php echo set_value('name'); ?&gt;" size="50" /&gt;
                
                <h3>Product Description</h3>
                &lt;textarea name="description" cols="" rows="" style="width:50%; height:100px;"&gt;&lt;?php echo set_value('description'); ?&gt;&lt;/textarea&gt;
                
                <h3>Product Image</h3>
                &lt;input type="file" name="userfile" size="50" /&gt;
                
                <div><br />&lt;input type="submit" value="Submit" /&gt;&lt;/div>
                
                &lt;/form&gt;
            </div>
            <div id="footer_area">
                <div class="footer_bg_left">
                </div>
                <div class="footer_bg_middle">
                    &lt;?php include_once "include/footer.php"; ?&gt;
                </div>
                <div class="footer_bg_right">
                </div>
            </div>
        </div>
    </div>
</div>
&lt;/body&gt;
&lt;/html&gt;
#3

[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.




Theme © iAndrew 2016 - Forum software by © MyBB