I have a form code html like this, but it's error for checkbox question, someone plase help my problem.
if(empty($tampil_pertanyaan)){
echo "<tr><td colspan=\"6\">Data tidak tersedia</td></tr>";
}else{
$no = 1; //for question
$no2 = 0; //for array
foreach($tampil_pertanyaan as $row)
{
<tr>
<td><input type="checkbox" class="w3-check" name="ket_jawaban[<?php echo $no2;?>]" id="ket_jawaban[<?php echo $no2;?>]" value="<?php echo $row->pil1;?>" oninput="this.className = ''"></td>
<td> <?php echo $row->pil1;?></td>
</tr>
<tr>
<td><input type="checkbox" class="w3-check" name="ket_jawaban[<?php echo $no2;?>]" id="ket_jawaban[<?php echo $no2;?>]" value="<?php echo $row->pil2;?>" oninput="this.className = ''"></td>
<td> <?php echo $row->pil2;?></td>
</tr>
<tr>
<td><input type="checkbox" class="w3-check" name="ket_jawaban[<?php echo $no2;?>]" id="ket_jawaban[<?php echo $no2;?>]" value="<?php echo $row->pil3;?>" oninput="this.className = ''"></td>
<td> <?php echo $row->pil3;?></td>
</tr>
$no++;
$no2++;
}
And i my controller (i use Codeigniter)
public function insert_jawaban(){
// Proses pemvalidasian data yg di input
$this->form_validation->set_rules('ket_jawaban[]', 'ket_jawaban', 'trim|xss_clean');
if ($this->form_validation->run() == FALSE){
echo validation_errors(); // tampilkan apabila ada error
}else{
//Insert ke tabel jawaban
$result = array();
foreach($_POST['ket_jawaban'] AS $key => $val){
$result[] = array(
"id_jawaban" => '',
"user" => $_POST['user'][$key],
"ket_jawaban" => $_POST['ket_jawaban'][$key],
"id_pilgan" => $_POST['id_pilgan'][$key],
"id_pertanyaan" => $_POST['id_pertanyaan'][$key],
"id_survey" => $_POST['id_survey'][$key],
"nama" => $_POST['nama_user'][$key],
"unit" => $_POST['unit_user'][$key],
"jenis" => $_POST['jenis_user'][$key]
);
}
$res = $this->db->insert_batch('jawaban', $result);
}
why every time I checked always only returns one value, even though I checked three.
before I apologize if there is any wrong in my question is because I am newbie here. Thanks and please be advised
Aucun commentaire:
Enregistrer un commentaire