I created a form in CI framework with 60 fields, and the database works. now I want to separate some fields and send it to another table, which linked to primary table (with relatioship, of course). so I hide some fields, and show it if the radio button checked as "yes" :
<!-- other fields -->
<div><label class="control-label" for="imp_status">3rd Party</label>
<div class="controls">
<table>
<tr>
<td><input type="radio" name="imp_status" id="imp_status_yes" value="1" onclick="javascript:importirCheck()"> Yes</td>
<td><input type="radio" name="imp_status" id="imp_status_no" value="0" onclick="javascript:importirCheck()"> No</td>
</tr>
</table>
</div>
</div>
<div style="display:none" id="info_imp">
<fieldset> somefields </fieldset>
</div>
<!-- other fields -->
script :
function importirCheck() {
if (document.getElementById('imp_status_no').checked) {
document.getElementById('info_imp').style.display = 'none';
$("#imp_status_no").val("");
}
else {
document.getElementById('info_imp').style.display = 'block';
$("#imp_status_yes").val("");
$("#imp_comp_name").val("");
...
}
}
the view is working, but now I'm confused how I should get the value (especially from imp_status because there are 2 id) for my database. there's save button at the end of the form and it linked to another script. I sent other values from that script. now I have table_primary (.., imp_status, id_imp,..) and table_imp (id_imp,...). when there's no 3rd party, I want the imp_status column save "0" & set id_imp to NULL/0 (in table_primary). but if there's a 3rd party, imp_status column should save "1" & save all info about this 3rd party (to table_imp with primary key id_imp). is this the right way (for script)? how should I modify the model and controller? this is my current controller (no imp_status and id_imp yet):
...
$imp_comp_name=$this->input->post("imp_comp_name");
$this->form_m->set_imp_comp_name($imp_comp_name);
$imp_comp_dir=$this->input->post("imp_comp_dir");
$this->form_m->set_imp_comp_dir($imp_comp_dir);
...
$result = $this->form_m->insert();
and this is my current model :
// there are properties & setters
public function insert(){
$sql = "INSERT INTO table_primary
(...,imp_comp_name,...) VALUES (...,'".$this->imp_comp_name."',...)";
return $this->db->query($sql);
}
I hope my question isn't confusing. links to read and learned are very welcomed, thanks.