至少选中一个复选框时如何将值发布到数据库中

时间:2018-08-17 10:48:11

标签: javascript html continuous-integration

我的带有复选框验证脚本的视图。我希望当我选中一个复选框时,应该存储与其相关的数据。

<form action="<?php echo site_url('need_assesment/insertservice'); ?>" [enter image description here][1]method="post">
        <div class="col-lg-11 col-md-5 col-sm-8 col-xs-9 bhoechie-tab-container">
            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 bhoechie-tab-menu">
              <div class="list-group">
                <?php foreach($member_details as $members){?>
                <a href="<?php echo base_url('index.php/need_assesment/req_questions/'.$m_id."/".$members->id);?>" class="list-group-item active text-center">
                  <br/><?php echo $members->member_name; ?>

                </a>

                <?php }?>
              </div>
            </div>


               <div class="col-lg-10 col-md-9 col-sm-9 col-xs-9 bhoechie-tab">
                <!-- flight section -->

                <div class="bhoechie-tab-content active">
                    <center>
                        <table  style="width:100%" id="zero_config" class="table table-striped table-bordered">
                         <col width="45%">
                         <col width="30%">
                         <col width="25%">
                         <col width="10%">
                        <tr>
                                <td>
                                    Requirements
                                </td>
                                <td>
                                    Schemes & Solution
                                </td>
                                <td>
                                    Process  
                                </td>
                                <td>
                                    Fees 
                                </td>
                        </tr>
                        <?php foreach ($requirement_details as $details) { ?>
                        <tr>
                                <td>

                                   <?php echo $details->Question ?>
                                </td>

                                <td>
                                 <input type="hidden" value="<?php echo $member_details[0]->id ?>" name="member_id[]">
                                <input type="hidden" value="<?php echo $m_id ?>" name="membership_id[]">
                                <input type="hidden" value="1" name="service_id[]">
                                   b 
                                </td>
                                <td>
                                   c 
                                </td>
                                <td>
                                   <label class="checkbox-inline" data-id="1" ><input type="checkbox"  name="a-1" value="A1">Rs=100</label><br><br>

                                </td>
                        </tr>    
                           <?php }  ?> 

                        </table>

                        <div class="act"><p><b>TOTAL =</b></p>
                        <p><b>GRAND TOTAL=</b></p>
                        </div>

                    </center>
                </div>

                <!-- train section -->


        </div>



                    </div>

        <div class="card-body">                                       
                            <a  href="<?php echo base_url('index.php/need_assesment/acknowledgement'); ?>"><input type="submit"  name="submit" value="PROCEED"  id="checkBtn" style="margin-left:40%;"  class="btn btn-success"> </a> 
                      </div>
                </div>
            </div>
        </div>

</form>      

                </script>
                <script type="text/javascript">
$(document).ready(function () {
    $('#checkBtn').click(function() {
      checked = $("input[type=checkbox]:checked").length;

      if(!checked) {
        alert("You must check at least one checkbox.");
        return false;
      }

    });
});

</script>

控制器

  public function insertservice(){
       $mid=$this->input->post('membership_id');
      $data =array();
    $id=$this->input->post('member_id');
    $service_id=$this->input->post('service_id');


    for ($i = 0; $i < count($this->input->post('member_id')); $i++) {
    $data[$i] = array(
        'member_id'=>$id[$i],
        'service_id'=>$service_id[$i]
    );
    }

    $this->db->insert_batch('selected_services',$data);
    $this->req_questions($mid[0],$data[0]['member_id']);


}

图片:

Image

0 个答案:

没有答案