// 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]'
),
);
}