$(document).ready(function(){
var family_number = 2;
$('#add-family-btn').click(function(){
$('#add-family').append(`
<h3 id="family-count">${family_number}.</h3>
<div class="form-group zbot">
<div class="col-md-1"></div>
<label class="col-md-2 control-label" style="color: red;"><b>Last Name</b></label>
<div class="col-md-3">
<div class="input-group mb-md input-group-icon">
<input type="text" name="familylastname[]" class="form-control" placeholder="">
</div>
</div>
<label class="col-md-2 control-label"><b>First Name</b></label>
<div class="col-md-3">
<div class="input-group mb-md input-group-icon">
<input type="text" name="familyfirstname[]" class="form-control" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-1"></div>
<label class="col-md-2 control-label" style="color: red;"><b>Relationship</b></label>
<div class="col-md-3">
<div class="input-group mb-md input-group-icon">
<input type="text" name="familyrelationship[]" class="form-control" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-1"></div>
<label class="col-md-2 control-label" style="color: red;"><b>Sex</b></label>
<div class="col-md-3">
<div class="input-group mb-md input-group-icon">
<select name="familysex[]" class="form-control">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-1"></div>
<label class="col-md-2 control-label" style="color: red;"><b>Age</b></label>
<div class="col-md-3">
<div class="input-group mb-md input-group-icon">
<input type="text" name="familyage[]" class="form-control" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-1"></div>
<label class="col-md-2 control-label" style="color: red;"><b>Civil Status</b></label>
<div class="col-md-3">
<div class="input-group mb-md input-group-icon">
<select name="civilstatus[]" class="form-control">
<option value="1 – Single">1 – Single</option>
<option value="2 – Married">2 – Married</option>
<option value="3 – Widowed">3 – Widowed</option>
<option value="4 – Legally Separated">4 – Legally Separated</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-1"></div>
<label class="col-md-2 control-label" style="color: red;"><b>Indicate if Solo Parent</b></label>
<div class="col-md-3">
<div class="input-group mb-md input-group-icon">
<select name="soloparent[]" class="form-control">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-1"></div>
<label class="col-md-2 control-label" style="color: red;"><b>Highest Educational Attainment</b></label>
<div class="col-md-3">
<div class="input-group mb-md input-group-icon">
<select name="highestattainment[]" class="form-control">
<option value="UNKNOWN">UNKNOWN</option>
<option value="N/A">N/A</option>
<option value="No Grade Completed">No Grade Completed</option>
<option value="Grade 1">Grade 1</option>
<option value="Grade 2">Grade 2</option>
<option value="Grade 3">Grade 3</option>
<option value="Grade 4">Grade 4</option>
<option value="Grade 5">Grade 5</option>
<option value="Grade 6">Grade 6</option>
<option value="Grade 7 / 1st Year HS">Grade 7 / 1st Year HS</option>
<option value="Grade 8 / 2nd Year HS">Grade 8 / 2nd Year HS</option>
<option value="Grade 9 / 3rd Year HS">Grade 9 / 3rd Year HS</option>
<option value="Grade 10 / 4th Year HS">Grade 10 / 4th Year HS</option>
<option value="Grade 11">Grade 11</option>
<option value="Grade 12">Grade 12</option>
<option value="Tech-Voc">Tech-Voc</option>
<option value="College">College</option>
<option value="Postgraduate">Postgraduate</option>
<option value="Others">Others</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-1"></div>
<label class="col-md-2 control-label" style="color: red;"><b>Occupation</b></label>
<div class="col-md-3">
<div class="input-group mb-md input-group-icon">
<input type="text" name="occupation[]" class="form-control" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-1"></div>
<label class="col-md-2 control-label" style="color: red;"><b>Estimated Monthly Income</b></label>
<div class="col-md-3">
<div class="input-group mb-md input-group-icon">
<input type="text" name="familymonthlyincome[]" class="form-control" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-1"></div>
<label class="col-md-2 control-label" style="color: red;"><b>Skills</b></label>
<div class="col-md-3">
<div class="input-group mb-md input-group-icon">
<select name="skills[]" class="form-control">
<option value="Plumbing">Plumbing</option>
<option value="Masonry">Masonry</option>
<option value="Carpentry">Carpentry</option>
<option value="Welding">Welding</option>
<option value="Automotive">Automotive</option>
<option value="Massage Therapy">Massage Therapy</option>
<option value="Electronics">Electronics</option>
<option value="Computer Technology">Computer Technology</option>
<option value="Sewing/ Upholstery Repair">Sewing/ Upholstery Repair</option>
<option value="Snack/Food Preparation">Snack/Food Preparation</option>
<option value="Meat Processing">Meat Processing</option>
<option value="Driving">Driving</option>
<option value="Cosmetology">Cosmetology</option>
<option value="Car Wash">Car Wash</option>
<option value="Others">Others</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-1"></div>
<label class="col-md-2 control-label" style="color: red;"><b>Whereabouts</b></label>
<div class="col-md-3">
<div class="input-group mb-md input-group-icon">
<input type="text" name="whereabouts[]"class="form-control" placeholder="">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-1"></div>
<label class="col-md-2 control-label" style="color: red;"><b>Type of Disability/Ailment, if any</b></label>
<div class="col-md-3">
<div class="input-group mb-md input-group-icon">
<input type="text" name="familytypeofdisability[]" class="form-control" placeholder="">
</div>
</div>
</div>
<hr>
`
);
family_number += 1;
});
});
В моей модели:
$childcontrolnodata = $this->input->post('childcontrolno');
$familylastnamedata = $this->input->post('familylastname[]');
$familyfirstnamedata = $this->input->post('familyfirstname[]');
$familyrelationshipdata = $this->input->post('familyrelationship[]');
$familysexdata = $this->input->post('familysex[]');
$familyagedata = $this->input->post('familyage[]');
$civilstatusdata = $this->input->post('civilstatus[]');
$soloparentdata = $this->input->post('soloparent[]');
$educationalattainmentdata = $this->input->post('highestattainment[]');
$occupationdata = $this->input->post('occupation[]');
$estimatedmonthlyincomedata = $this->input->post('familymonthlyincome[]');
$skillsdata = $this->input->post('skills[]');
$whereaboutsdata = $this->input->post('whereabout[]s');
$familytypedisabilitydata = $this->input->post('familytypeofdisability[]');
$value = array();
for ($i = 0; $i < count($familylastnamedata); $i++){
$value[$i] = array(
'child_control_no' => $childcontrolnodata,
'family_last_name' => $familylastnamedata[$i],
'family_first_name' => $familyfirstnamedata[$i],
'family_relationship' => $familyrelationshipdata[$i],
'family_sex' => $familysexdata[$i],
'family_age' => $familyagedata[$i],
'family_civil_status' => $civilstatusdata[$i],
'solo_parent' => $soloparentdata[$i],
'educational_attainment' => $educationalattainmentdata[$i],
'occupation' => $occupationdata[$i],
'estimated_monthly_income' => $estimatedmonthlyincomedata[$i],
'skills' => $skillsdata[$i],
'whereabouts' => $whereaboutsdata[$i],
'family_type_disability' => $familytypedisabilitydata[$i],
);
}
$this->db->insert_batch('tbl_profile_family',$value);