Regarding my project I want insert per employee{employee_no} many descriptions with voucher_no and amount, and many support document, so I have created my view page for descriptions and support document add multiple fields.
So I can add many fields as many as I want but I want to insert those data into my database normally when I insert data without descriptions and support documents.
It works perfectly but my requirement is to make this code to insert multiple descriptions and support documents.
this is my View page : fields to descriptions and support documents
<div class="form-group">
<div class="row colbox">
<div class="col-sm-offset-2 col-lg-8 col-sm-8 text-left">Description</div>
<div class="field_wrapper">
<input type="textarea" name="descrip[]" value="" size="35px" /><input type="text" name="voucher_no[]" value="" size="7px"/><input type="text" name="price[]" value=""size="7px"/>
<a href="javascript:void(0);" class="add_button" title="Add field"><img src="<?php echo base_url('images/add-icon.png'); ?>"/></a>
</div></div></div>
<div class="form-group">
<div class="row colbox">
<div class="col-sm-offset-2 col-lg-8 col-sm-8 text-left">SUPPORT DOCUMENT</div><br />
<div class="field_upload">
<input type="file" name="field_upload[]" value="" size="35px" />
<a href="javascript:void(0);" class="add_butt" title="Add field">
<img src="<?php echo base_url('images/add-icon.png'); ?>"/></a>
</div></div></div>
my controller :
function index()
{
//fetch data from department and designation tables
$data['department'] = $this->employee_model->get_department();
$data['designation'] = $this->employee_model->get_designation();
//$data['descrip'] = $this->employee_model->insert_descriptions();
//set validation rules
$this->form_validation->set_rules('employeeno', 'Employee No', 'trim|required|numeric');
$this->form_validation->set_rules('employeename', 'Employee Name', 'trim|required|callback_alpha_only_space');
$this->form_validation->set_rules('department', 'Department', 'callback_combo_check');
$this->form_validation->set_rules('designation', 'Designation', 'callback_combo_check');
$this->form_validation->set_rules('hireddate', 'Hired Date');
$this->form_validation->set_rules('salary', 'Salary', 'required|numeric');
$this->form_validation->set_rules('document', 'Document', 'trim');
$this->form_validation->set_rules('descrip', 'Description', 'trim');
if ($this->form_validation->run() == FALSE)
{
//fail validation
$this->load->view('employee_view', $data);
}
else
{
//pass validation
$data = array(
'employee_no' => $this->input->post('employeeno'),
'employee_name' => $this->input->post('employeename'),
'department_id' => $this->input->post('department'),
'designation_id' => $this->input->post('designation'),
'hired_date' => @date('Y-m-d', @strtotime($this->input->post('hireddate'))),
'salary' => $this->input->post('salary'),
'description' => $this->input->post('descrip'),
'document' => $this->input->post('filed_upload'),
);
//insert the form data into database
$this->db->insert('tbl_employee', $data);
I know I want to use foreach loop for descriptons and support documents but I don't know how to use it