无法在Codeigniter中获取多个复选框的值(第2部分)

时间:2017-03-03 04:03:17

标签: php jquery codeigniter checkbox

之前我确实问了同样的问题,但我不明白为什么它现在不起作用。当我单击打开模态(用于编辑功能)时,数据不会填充,只有role_id填充在模态中。它与jquery版本或Codeigniter新更新或其他东西有关吗?以下是我的代码。感谢你的善意。

查看/ rolelist.php

javascript就在这里

<script type="text/javascript">
                            $(document).ready(function(){
                                $('.edit-row').on('click',function(){
                                    var me = $(this);
                                    var editModal = $('#myModalEdit');
                                    editModal.find('#role_id').val(me.attr('data-roleID'));
                                    editModal.find('#role_name').val(me.attr('data-roleName'));
                                    editModal.find('#manage_user').val(me.attr('data-manageUser'));
                                    editModal.find('#manage_product').val(me.attr('data-manageProduct'));
                                    editModal.find('#manage_project').val(me.attr('data-manageProject'));
                                    editModal.find('#manage_timeline').val(me.attr('data-manageTimeline'));
                                    editModal.find('#fn_trace').val(me.attr('data-fnTrace'));
                                    editModal.find('#fn_mapper').val(me.attr('data-fnMapper'));
                                    editModal.find('#fn_testscript').val(me.attr('data-fnTestScript'));
                                    editModal.find('#fn_project').val(me.attr('data-fnProject'));
                                    $('#myModalEdit').modal('show');
                                });
                            });
</script> 

HTML代码

<!-- Modal -->
    <div class="modal fade" id="myModalEdit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Edit System Role <label id="role_name"></label></h4>
            </div>

        <form role="form" id="roleForm" action="<?php echo base_url().'admin/updateRole'; ?>" method= "POST">
            <div class="modal-body">
            <div class="form-group">
                <label>Role ID [Auto-generate by system]</label>                                    
                <input type="text" class="form-control" name="role_id" id="role_id" readonly>
            </div>
            <div class="form-group">
                <label>Role Name *</label>
                <input type="text" class="form-control" name="role_name" id="role_name">
            </div>
            <div class="form-group">
                <table class="table table-bordered table-striped table-condensed">
                    <thead style="background-color:#33658A; color:#FFF;">
                      <tr>
                                <th colspan="4"><strong><center>ADMIN FUNCTIONS</center></strong></th>
                                <th colspan="4"><strong><center>QA FUNCTIONS</center></strong></th>
                      </tr>
                      <tr>
                                <th><strong><center>MANAGE USER</center></strong></th>
                                <th><strong><center>MANAGE PRODUCT</center></strong></th>
                                <th><strong><center>MANAGE PROJECT</center></strong></th>
                                <th><strong><center>MANAGE TIMELINE</center></strong></th>
                                <th><strong><center>TRACE</center></strong></th>
                                <th><strong><center>MAPPER</center></strong></th>
                                <th><strong><center>TEST SCRIPT</center></strong></th>
                                <th><strong><center>PROJECT</center></strong></th>
                      </tr>
                    </thead>
                    <tbody>
                      <div class="checkbox">
                      <tr>
                          <td><input type="checkbox" name="manage_user" id="manage_user" value="manage_user" style="margin-left:20px"></td>                           
                          <td><input type="checkbox" name="manage_product" id="manage_product" value="manage_product" style="margin-left:20px"></td>                              
                          <td><input type="checkbox" name="manage_project" id="manage_project" value="manage_project" style="margin-left:20px"></td>                              
                          <td><input type="checkbox" name="manage_timeline" id="manage_timeline" value="manage_timeline" style="margin-left:20px"></td>                           
                          <td><input type="checkbox" name="fn_trace" id="fn_trace" value="fn_trace" style="margin-left:20px"></td>                            
                          <td><input type="checkbox" name="fn_mapper" id="fn_mapper" value="fn_mapper" style="margin-left:20px"></td>                             
                          <td><input type="checkbox" name="fn_testscript" id="fn_testscript" value="fn_testscript" style="margin-left:20px"></td>                             
                          <td><input type="checkbox" name="fn_project" id="fn_project" value="fn_project" style="margin-left:20px"></td>                              
                      </tr>
                      </div> <!-- end checkbox -->
                    </tbody>
                </table>
            </div>
            </div> <!-- end modal-body -->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                <button type="submit" value="submit" class="btn btn-primary" >Update Info</button>
            </div>
        </form>
        </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div> <!-- /.modalEdit -->

    <div class="col-lg-12">
                  <div class="content-panel">
                      <section id="unseen">
                        <table class="table table-bordered table-striped table-condensed">
                          <thead style="background-color:#33658A; color:#FFF;">
                          <tr>
                                <th rowspan="2"><h4><strong>ROLE ID</strong></h4></th>
                                <th rowspan="2"><h4><strong>ROLE NAME</strong></h4></th>
                                <th colspan="4"><h4><strong><center>ADMIN FUNCTIONS</center></strong></h4></th>
                                <th colspan="4"><h4><strong><center>QA FUNCTIONS</center></strong></h4></th>
                                <th rowspan="2"><h4><center><strong>ACTION</strong></center></h4></th>
                          </tr>
                          <tr>
                                <th><h4><strong>MANAGE USER</strong></h4></th>
                                <th><h4><strong>MANAGE PRODUCT</strong></h4></th>
                                <th><h4><strong>MANAGE PROJECT</strong></h4></th>
                                <th><h4><strong>MANAGE TIMELINE</strong></h4></th>
                                <th><h4><strong>TRACE</strong></h4></th>
                                <th><h4><strong>MAPPER</strong></h4></th>
                                <th><h4><strong>TEST SCRIPT</strong></h4></th>
                                <th><h4><strong>PROJECT</strong></h4></th>
                          </tr>
                          </thead>
                          <tbody>
                          <?php
                if(!empty($data_role)):
                foreach($data_role as $row)
                {
              ?>
              <tr>                  
                <td align="center"><?php echo $row->role_id; ?></td>                            
                <td><?php echo $row->role_name; ?></td>

              <?php
                echo '<td>'.$row->adm_manage_user.'</td>';
                echo '<td>'.$row->adm_manage_product.'</td>';
                echo '<td>'.$row->adm_manage_project.'</td>';
                echo '<td>'.$row->adm_manage_timeline.'</td>';
                echo '<td>'.$row->fn_trace.'</td>';
                echo '<td>'.$row->fn_mapper.'</td>';
                echo '<td>'.$row->fn_test_script.'</td>';
                echo '<td>'.$row->fn_project.'</td>';
                echo '<td class="text-center">';
              ?>
              <a href="<?php echo base_url().'admin/roleRemove/'.$row->role_id; ?>">
                <button type="button" data-hover="tooltip" title="Delete Role <?php echo $row->role_name; ?>" class="btn btn-default">
                    <i class="fa fa-times"></i>
                </button>
              </a>&nbsp;&nbsp;&nbsp;

              <a class="edit-row" href="javascript:" 
                data-roleID="<?php echo $row->role_id; ?>"
                data-roleName="<?php echo $row->role_name; ?>"
                data-manageUser="<?php echo $row->adm_manage_user; ?>"
                data-manageProduct="<?php echo $row->adm_manage_product; ?>"
                data-manageProject="<?php echo $row->adm_manage_project; ?>"
                data-manageTimeline="<?php echo $row->adm_manage_timeline; ?>"
                data-fnTrace="<?php echo $row->fn_trace; ?>"
                data-fnMapper="<?php echo $row->fn_mapper; ?>"
                data-fnTestScript="<?php echo $row->fn_test_script; ?>"
                data-fnProject="<?php echo $row->fn_project; ?>"
              > 
              <button type="button" data-hover="tooltip" title="Edit Role <?php echo $row->role_name; ?>" class="btn btn-default">
                <i class="fa fa-pencil"></i>
              </button>
              </a>

              <?php
                echo '</td>';
                echo '</tr>';
                }
                endif;
              ?>
                          </tbody>
                      </table>
                      </section>
              </div><!-- /content-panel -->
            </div><!-- /col-lg-12 -->           

1 个答案:

答案 0 :(得分:0)

如果所有复选框彼此相关,则使用相同的name

<td><input type="checkbox" name="manage[]" id="manage_user" value="manage_user" style="margin-left:20px"></td> 
<td><input type="checkbox" name="manage[]" id="manage_product" value="manage_product" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage[]" id="manage_project" value="manage_project" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage[]" id="manage_timeline" value="manage_timeline" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage[]" id="fn_trace" value="fn_trace" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage[]" id="fn_mapper" value="fn_mapper" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage[]" id="fn_testscript" value="fn_testscript" style="margin-left:20px"></td>
<td><input type="checkbox" name="manage[]" id="fn_project" value="fn_project" style="margin-left:20px"></td> 

并使用名称$this->input->post('manage');

访问复选框值