我想问一下作为Codeigniter的新手。
我想在CI中制作动态表单,如果我想增加表单,我可以点击"增加"那么表格会在底部增加,如果点击"增加"太多次我点击"删除"然后表格会减少..
我使用动态表单制作了它,但是当我想将它保存到SQL数据库时出现问题。
我的代码是这样的:
tambah_material.php
<div id="isi">
<h1>Material Order</h1><br />
<a href="<?php echo base_url(); ?>index.php/adminweb/calon"><div class="submitButton">List Material Order</div></a>
<br><br><br><br><table width="100%">
<form method="post" id="myfrm" action="<?php echo base_url(); ?>index.php/adminweb/simpanmaterial">
<tr><td width="200">Project Name</td><td width="10" align="center">:</td><td><input type="text" class="input" name="nama_lengkap" size="100" /></td></tr>
<tr><td width="200">Project Status</td><td width="10" align="center">:</td><td>
<select name="nama" class="input">
<option value="Under Project Implementation" selected="selected">Under Project Implementation</option><option value="Under Warranty">Under Warranty</option>
<option value="Project Warranty">Project Warranty</option><option value="Out of Warranty">Out of Warranty</option>
</select></td></tr>
<tr><td width="200">Site/Hop Name</td><td width="10" align="center">:</td><td><input type="text" class="input" name="nim" size="50" /></td></tr>
<tr><td width="200">Material Description</td><td width="10" align="center">:</td><td>
<script type="text/javascript">
$(document).ready(function() {
var nomor = 0;
var status="";
$(".tambah").click(function(){
nomor ++;
$('#konten').append(
'<tr class="baris">'
+ '<input name="nomor[]" value="'+ nomor +'" type="hidden"></td>'
+ '<td><input name="tempat_'+ nomor +'" type="text" size="40"></td>'
+ '<td><input name="sn_'+ nomor +'" type="text" size="60"></td>'
+ '<td><input type="button" id="hapus" value="Hapus"></td></tr>'
);
});
$("#hapus").live('click', function () {
$(this).parents(".baris").remove();
});
$("#myfrm").validate({
debug: false,
rules: {
},
messages: {
},
});
});
function tampilTabel()
{
if(status=="")
{
$('#tabel').slideDown();
status="1";
}
else
{
$('#tabel').slideUp();
status="";
}
}
</script>
<a class="tambah" style="cursor:pointer; padding:6px; border:1px solid #000; background-color:#FF9900; color:#000000;">Tambah Form</a>
<br><br>
<tr><td></td><td></td><td>Nama Material :
                                                            
Serial Number :</td>
</tr>
<tr id="konten"><td></td><td>
<tr><td width="150">Reason/Suspect Problem</td><td width="10">:</td><td>
<select name="jk" class="input">
<option value="Interference" selected="selected">Interference</option><option value="Lightning Strike">Lightning Strike</option>
<option value="Leakage Shelter">Leakage Shelter</option><option value="Replace Broken One">Replace Broken One</option>
<option value="Borrow">Borrow</option><option value="Others">Others</option>
</select>
</td></tr>
<tr><td width="200">Returned to RWH</td><td width="10" align="center">:</td><td><input type="text" class="input" name="alamat" size="70"/></td></tr>
<tr><td width="200">Quantity</td><td width="10" align="center">:</td><td><input type="text" class="input" name="jml" size="70"/></td></tr>
<tr><td width="200">Status</td><td width="10" align="center">:</td><td>
<select name="status" class="input">
<option value="yes" selected="selected">Yes</option><option value="no">No</option></select>
</select>
</td></tr>
<tr><td width="200"></td><td width="10" align="center"></td><td><input type="submit" value="Simpan Data" class="input" /> <input type="reset" value="Hapus" class="input" /></td></tr>
</form>
</table>
</div>
adminweb.php(控制器)
function simpanmaterial()
{
$data=array();
$data2=array();
$session=isset($_SESSION['username_belajar']) ? $_SESSION['username_belajar']:'';
if($session!=""){
$pecah=explode("|",$session);
$data["username"]=$pecah[0];
$data["nama"]=$pecah[1];
$data["status"]=$pecah[2];
$data['scriptmce'] = $this->scripttiny_mce();
if($data["status"]=="admin"){
$tgl = " %Y-%m-%d";
$time = time();
$in["nama"]=$this->input->post('nama');
$in["nim"]=$this->input->post('nim');
$in["nama_lengkap"]=$this->input->post('nama_lengkap');
$in["alamat"]=$this->input->post('alamat');
$in["jk"]=$this->input->post('jk');
$in["jml"]=$this->input->post('jml');
$in["status"]=$this->input->post('status');
$in["tempat_1"]=$this->input->post('tempat_1');
$in["tempat_2"]=$this->input->post('tempat_2');
$in["tempat_3"]=$this->input->post('tempat_3');
$in["tempat_4"]=$this->input->post('tempat_4');
$in["sn_1"]=$this->input->post('sn_1');
$in["sn_2"]=$this->input->post('sn_2');
$in["sn_3"]=$this->input->post('sn_3');
$in["sn_4"]=$this->input->post('sn_4');
$in["tanggal"] = mdate($tgl,$time);
$in["penulis"] = $data["username"];
if($in["nama_lengkap"]=="" || $in["nim"]=="" || $in["alamat"]=="")
{
echo "Data masih kosong..!!!";
}
else{
$this->Admin_model->Simpan_Artikel("tbl_mahasiswa",$in);
echo "<meta http-equiv='refresh' content='0; url=".base_url()."index.php/adminweb/insbaru'>";
}
}
else{
?>
<script type="text/javascript" language="javascript">
alert("Anda tidak berhak masuk ke Control Panel Admin...!!!");
</script>
<?php
echo "<meta http-equiv='refresh' content='0; url=".base_url()."index.php/'>";
}
}
else{
?>
<script type="text/javascript" language="javascript">
alert("Anda belum Log In...!!!\nAnda harus Log In untuk mengakses halaman ini...!!!");
</script>
<?php
echo "<meta http-equiv='refresh' content='0; url=".base_url()."index.php/'>";
}
}
感谢您的帮助
最诚挚的问候, Karisma