javascript - Codeigniter form in modal bootstrap failed passing multiple chekbox using jquery -


i have form in modal bootstrap. in codeigniter form, left form_open blank, because want page still not move page. code :

 <div class="modal-body">     <?php     $properties = array('class' => 'form-horizontal', 'id' => 'myform', 'name' => 'myform');     echo form_open("", $properties);     ?>      <fieldset>         <div class="control-group">             <label class="control-label">jenis request :</label>             <div class="controls" id="chekboxes">                 <label class="checkbox inline"><input type="checkbox" name="request[]" id="login" value="login" /> login </label>                 <label class="checkbox inline"><input type="checkbox" name="request[]" id="printer" value="printer"/> printer </label>                 <label class="checkbox inline"><input type="checkbox" name="request[]" id="monitor" value="monitor"/> monitor</label>                 <label class="checkbox inline"><input type="checkbox" name="request[]" id="computer" value="computer"/> computer</label>                 <label class="checkbox inline"><input type="checkbox" name="request[]" id="network" value="network"/> network</label>                 <label class="checkbox inline"><input type="checkbox" name="request[]" id="other" value="lain-lain" /> other</label>              </div>         </div>          <div class="control-group hidden-phone">             <label class="control-label" for="keluhan" >description: </label>             <div class="controls">                 <textarea class="cleditor" name="keluhan" id="keluhan" rows="3" autofocus="autofocus"></textarea>             </div>         </div>          <div class="form-actions">             <button type="submit" class="btn btn-primary" id="submit">kirim</button>             <button type="reset" class="btn" id="reset">cancel</button>         </div>     </fieldset>     <?php echo form_close(); ?> </div> 

see, use jquery insert new data on database :

$(document).on('submit', '#myform', function() {         $('#myform').block({             message: '<h2>sedang mencari</h2>',             css: {border: '3px solid #a00'}         });          var request = $("input[name='request[]']:checked");         var keluhan = $("#keluhan").val();            $.ajax({             url: '<?php echo base_url() . 'direksi/control_direksi/mdrequest' ?>',             type: 'post',             data: {request: request,                 keluhan: keluhan},             datatype: 'json',             success: function(data) {                 alert("insert success");                 $("mymodal").hide();             }         });          return false;     }); 

and php action

public function mdrequest() {      var_dump($_post);  } 

my page refreshed without affected. how check if post success ? , how passed multiple checkbox using jquery, wrong on code above ? appreciated.

you can pass values using array variable. store checked element inside array variable :

var request = $("input[name='request[]']:checked").map(function(i,e) {     return $(this).val(); }).get(); 

to check post request success or not, can check via network tab chrome browser, , see ajax request success or not. second, display output using console.log(). print out output of var_dump. :

 success: function(data) {     console.log(data);     $("mymodal").hide();  } 

in server side, can use function :

public function mdrequest() {   print_r($this->input->post());   // or print_r($this->input->post('request')); } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -