简体   繁体   中英

Data not inserted using modal bootstrap and codeigniter

I'm not familiar using javascript & jquery in modal bootstrap, and need your advice. I create a modal to insert data into database. but when i click 'save' button nothing happen. I hope you can help me to check if there's something wrong with my codes. I spent a weeks searching if there any error in my codes.

Here is my view :

$(document).on("click", ".open-InputNilaiDialog", function () {
        var myFormId = $(this).data('id');
        $(".modal-body #nim").val( myFormId );
    });

<div class="modal fade" id="inputNilaiDialog" role="dialog" >
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Form Nilai</h4>
              </div>
              <div class="modal-body">
                <p>Contoh</p>
            <form class="form-horizontal" method="post" action="<?php echo base_url().'tutor/mtk_np/simpan'?>">
              <div class="box-body">
              <div class="form-group">
                  <div class="col-sm-10">
                    <input type="hidden" class="form-control" id="idtutor" name="idtutor" value="<?php echo $this->session->userdata('username'); ?>"/>
                  </div>
                </div>
                <div class="form-group">
                  <label for="nim" class="col-sm-2 control-label">NIM</label>

                  <div class="col-sm-10">
                    <input type="text" class="form-control" id="nim" name="nim" readonly />
                  </div>                  
                </div>  
                <div class="form-group">
                  <label for="nilai" class="col-sm-2 control-label">Nilai</label>

                  <div class="col-sm-10">
                    <input type="text" class="form-control" id="nilai" name="nilai" readonly />
                  </div>                  
                </div>  

                <!-- START INPUT HIDDEN-->
                <input type="hidden" class="form-control" id="kd_mtk" name="kd_mtk" value="<?php echo $row->kode_mtk; ?>"/>
                <input type="hidden" class="form-control" id="kelas" name="kelas" value="<?php echo $row->kelas; ?>"/>
                <!-- END INPUT HIDDEN-->
              <div class="modal-footer">
                <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Tutup</button>
                <button type="button" class="btn btn-primary">Simpan</button>
              </div>
              </form>
              </div>
            </div>           
          </div>         
        </div>

This is my controller :

public function simpan(){
    $data = array (
    'idtutor'           => $this->input->post('idtutor'),
    'nim'               => $this->input->post('nim'),       
    'kd_mtk'            => $this->input->post('kd_mtk'),
    'kelas'             => $this->input->post('kelas'),
    'nilai'             => $this->input->post('nilai')
    );
    $this->mtk_model->simpan($data);
    redirect(base_url(). "mtk_np");
}

And my model :

function simpan($data)
{
    $this->db->insert("nilai_tutorial", $data);     
}

You can enable the debug option in config.php & database.php

In config.php you make the following changes

$config['log_threshold'] = 1; // You may also set the same to 2 or 3 depending on the level of issue you want to track.

In database.php, make the following changes

$db['default']['db_debug'] = TRUE;

What this will do is, it will start logging in any sort of errors that might be happening. This will help you check in if you having some missing value or whatever exception that comes through. With the newer version of CI, i have experienced this issue, if there is any issue like in query, the system dose not throw back errors, rather it just suppresses the same, makes the screen go empty / break the execution or so.

Button is not a submit type.

Change this

<button type="button" class="btn btn-primary">Simpan</button>

To this

<button type="submit" class="btn btn-primary">Simpan</button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM