Welcome Guest, Not a member yet? Register   Sign In
codeigniter
#2

set_value() is meant to be used in a view, not a controller.

If you're submitting the data in a POST from a form, you should retrieve the data from $this->input->post(), as you've attempted with request_email and request_text.

If you just want to retrieve the data from the database based on an ID, as implied by your query at the beginning of the method, then you should fill your array from the query result, rather than attempting to fill it from $this->input->post().

Below are two (untested) examples, the first pulling the data from the POST, the second pulling it from the database.


PHP Code:
   // Insert the data submitted by the form
 
   public function copy_hauler($hauler_id)
 
   {
 
       // Validate the form
 
       $this->form_validation->set_rules($this->getValidationRules());
 
       if ($this->form_validation->run() === false) {
 
           return false;
 
       }

 
       // Get the POST data
 
       $following = array(
 
           'company'               => $this->input->post('company'),
 
           'hauler_name'           => $this->input->post('hauler_name'),
 
           'hauler_address_1'      => $this->input->post('hauler_address_1'),
 
           'hauler_city'           => $this->input->post('hauler_city'),
 
           'hauler_state'          => $this->input->post('hauler_state'),
 
           'hauler_zipcode'        => $this->input->post('hauler_zipcode'),
 
           'hauler_phone'          => $this->input->post('hauler_phone'),
 
           'hauler_fax'            => $this->input->post('hauler_fax'),
 
           'hauler_email'          => $this->input->post('hauler_email'),
 
           'hauler_website'        => $this->input->post('hauler_website'),
 
           'hauler_contact_name'   => $this->input->post('hauler_contact_name'),
 
           'hauler_contact_number' => $this->input->post('hauler_contact_number'),
 
           'request_email'         => $this->input->post('request_email'),
 
           'request_text'          => $this->input->post('request_text'),
 
       );

 
       // Insert, return true on success, false on failure.
 
       $this->db->insert('haulers'$following);
 
       return $this->db->affected_rows() == '1';
 
   }

 
   // Insert the data retrieved from the database
 
   public function db_copy_hauler($hauler_id)
 
   {
 
       $hauler_id = (int) $hauler_id;

 
       // Get the data for the provided ID
 
       $this->db->select('company,hauler_name,hauler_address_1,hauler_city,hauler_state,hauler_zipcode,hauler_phone,hauler_fax,hauler_email,hauler_website,hauler_contact_name,hauler_contact_number,request_email,request_text');
 
       $this->db->from('haulers');
 
       $this->db->where('hauler_id'$hauler_id);

 
       $query $this->db->get();
 
       if ($query->num_rows() < 1) {
 
           // No data found, invalid ID?
 
           return false;
 
       }

 
       // Get the first row of data, then populate $following for 
 
       // insert. You could just send $row, but you may want to do
 
       // something else with the data, first.
 
       $row $query->row_array();
 
       $following = array();
 
       foreach ($row as $key => $value) {
 
           $following[$key] = $value;
 
       }

        // Insert, return true on success, false on failure.
 
       $this->db->insert('haulers'$following);
 
       return $this->db->affected_rows() == '1';
 
   }

    // http://www.codeigniter.com/user_guide/libraries/form_validation.html#setting-rules-using-an-array
 
   protected function getValidationRules()
 
   {
 
       return array(
 
           array(
 
               'field' => 'company',
 
               'label' => 'Company',
 
               'rules' => 'max_length[255]'
 
           ),
 
       );
 
   
Reply


Messages In This Thread
codeigniter - by bhumi - 05-13-2015, 05:13 AM
RE: codeigniter - by mwhitney - 05-13-2015, 07:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB