Encoder form that does not receive the correct user ID

advertisements

I have a table with all my user on it and I have a button where I can click on it and loads bootstrap modal, the bootstrap modal has is a form.

But for some reason the form_open all ways shows the last id in the table.

http://localhost/project/admin/users/delete_user/17

How can I make it so when I click on each delete button the form on model will show correct ID.

<?php echo Modules::run('admin/common/header/index');?>
<div id="wrapper">
<?php echo Modules::run('admin/common/menu/index');?>
<div id="page-wrapper">
<div id="page-inner">

<div class="panel panel-default">
<div class="panel-heading clearfix">
    <div class="pull-left" style="padding-top: 7.5px"><h1 class="panel-title"><i class="fa fa-list"></i> <?php echo $title;?></h1></div>
    <div class="pull-right">
        <a href="<?php echo base_url('admin/users/add');?>" role="button" class="btn btn-success"><i class="fa fa-plus"></i> Add</a>
    </div>
</div>
<div class="panel-body">
<?php echo Modules::run('admin/message/messages/index');?>
<div class="table-responsive">
<table  class="table table-striped table-bordered table-hover">
    <thead>
        <tr>
            <th>User ID</th>
            <th>Username</th>
            <th class="text-right">User Status</th>
            <th class="text-right">Date Registered</th>
            <th class="text-right">Update User Info</th>
        </tr>
    </thead>
    <tbody>
    <?php foreach ($users as $user) { ?>
        <tr>
            <td><?php echo $user['user_id'];?></td>
            <td><?php echo $user['username'];?></td>
            <td class="text-right"><?php echo $user['status'];?></td>
            <td class="text-right"><?php echo $user['date_added'];?></td>
            <td class="text-right">
            <a data-toggle="modal" data-target="#myModal" role="button" class="btn btn-danger"><i class="fa fa-trash"></i> Remove User</a>
            <a href="<?php echo $user['update_user_info'];?>" role="button" class="btn btn-primary">Update User Info</a>
            </td>
        </tr>
    <?php } ?>
    </tbody>
</table>
</div>
</div>
</div>

<!-- Modal -->
<?php echo form_open_multipart('admin/users/delete_user' .'/'.  $user['user_id']);?>
<div class="modal fade" id="myModal" 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-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Confrm Delete Notice</h4>
</div>
<div class="modal-body">
<div class="alert alert-danger text-center">
<h4>You are about to delete this user. <?php echo $user['user_id'];?></h4>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Confirm Delete</button>
</div>
</div>
</div>
</div>
<?php echo form_close();?>

</div><!-- # Page Inner End  -->
</div><!-- # Page Wrapper End  -->
</div><!-- #.WRAPPER  -->
<?php echo Modules::run('admin/common/footer/index');?>
<script type="text/javascript">
$('#myModal').on('shown.bs.modal', function () {
  $('#myInput').focus()
});

Update:

Form In Loop

http://localhost/project/admin/users/delete_user/15 each model that pop up does not show correct id.

<?php echo Modules::run('admin/common/header/index');?>
<div id="wrapper">
<?php echo Modules::run('admin/common/menu/index');?>
<div id="page-wrapper">
<div id="page-inner">

<div class="panel panel-default">
<div class="panel-heading clearfix">
    <div class="pull-left" style="padding-top: 7.5px"><h1 class="panel-title"><i class="fa fa-list"></i> <?php echo $title;?></h1></div>
    <div class="pull-right">
        <a href="<?php echo base_url('admin/users/add');?>" role="button" class="btn btn-success"><i class="fa fa-plus"></i> Add</a>
    </div>
</div>
<div class="panel-body">
<?php echo Modules::run('admin/message/messages/index');?>
<div class="table-responsive">
<table  class="table table-striped table-bordered table-hover">
    <thead>
        <tr>
            <th>User ID</th>
            <th>Username</th>
            <th class="text-right">User Status</th>
            <th class="text-right">Date Registered</th>
            <th class="text-right">Update User Info</th>
        </tr>
    </thead>
    <tbody>
    <?php foreach ($users as $user) { ?>
        <tr>
            <td><?php echo $user['user_id'];?></td>
            <td><?php echo $user['username'];?></td>
            <td class="text-right"><?php echo $user['status'];?></td>
            <td class="text-right"><?php echo $user['date_added'];?></td>
            <td class="text-right">
            <a data-toggle="modal" data-target="#myModal" role="button" class="btn btn-danger"><i class="fa fa-trash"></i> Remove User</a>
            <a href="<?php echo $user['update_user_info'];?>" role="button" class="btn btn-primary">Update User Info</a>
            </td>
        </tr>
        <!-- Modal -->
        <?php echo form_open_multipart('admin/users/delete_user' .'/'.  $user['user_id']);?>
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
        <div class="modal-content">
        <div class="modal-header">
        <h4 class="modal-title" id="myModalLabel">Confirm Delete Notice</h4>
        </div>
        <div class="modal-body">
        <div class="alert alert-danger text-center">
        <h4>You are about to delete this user. <?php echo $user['user_id'];?></h4>
        </div>
        </div>
        <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Confirm Delete</button>
        </div>
        </div>
        </div>
        </div>
        <?php echo form_close();?>
    <?php } ?>
    </tbody>
</table>
</div>
</div>
</div>
</div><!-- # Page Inner End  -->
</div><!-- # Page Wrapper End  -->
</div><!-- #.WRAPPER  -->
<?php echo Modules::run('admin/common/footer/index');?>
<script type="text/javascript">
$('#myModal').on('shown.bs.modal', function () {
  $('#myInput').focus()
});
</script>


Do it separate from the Table loop like this:

<table  class="table table-striped table-bordered table-hover">
<thead>
    <tr>
        <th>User ID</th>
        <th>Username</th>
        <th class="text-right">User Status</th>
        <th class="text-right">Date Registered</th>
        <th class="text-right">Update User Info</th>
    </tr>
</thead>
<tbody>
<?php foreach ($users as $user) { ?>
    <tr>
        <td><?php echo $user['user_id'];?></td>
        <td><?php echo $user['username'];?></td>
        <td class="text-right"><?php echo $user['status'];?></td>
        <td class="text-right"><?php echo $user['date_added'];?></td>
        <td class="text-right">
        <a data-toggle="modal" data-target="#myModal<?php echo $user['user_id'];?>" role="button" class="btn btn-danger"><i class="fa fa-trash"></i> Remove User</a>
        <a href="<?php echo $user['update_user_info'];?>" role="button" class="btn btn-primary">Update User Info</a>
        </td>
    </tr>
    <?php echo form_close();?>
<?php } ?>
</tbody>
</table>

// Separate from Table
<?php foreach ($users as $user) { ?>
<?php echo form_open_multipart('admin/users/delete_user' .'/'.  $user['user_id']);?>
    <div class="modal fade" id="myModal<?php echo $user['user_id'];?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
    <div class="modal-content">
    <div class="modal-header">
    <h4 class="modal-title" id="myModalLabel">Confirm Delete Notice</h4>
    </div>
    <div class="modal-body">
    <div class="alert alert-danger text-center">
    <h4>You are about to delete this user. <?php echo $user['user_id'];?></h4>
    </div>
    </div>
    <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    <button type="submit" class="btn btn-primary">Confirm Delete</button>
    </div>
    </div>
    </div>
    </div>
    <?php echo form_close();?>
<?php } ?>

Also separate Model ID for each Model Window data-target="#myModal<?php echo $user['user_id'];?>" and id="myModal<?php echo $user['user_id'];?>"