manageuser.php
<form method="post" action="" name="myform">
<table width="100%">
<tr>
<th><input type="checkbox" id="selectall" onClick="selectAll(this)"></th>
<th>Id</th>
<th>Username</th>
<th>UserType</th>
<th>Address</th>
<th>Contact</th>
<th>Status</th>
<th>Action</th>
</tr>
<?php
$id= 1;
foreach($userlist as $user)
{
?>
<tr>
<td><input type="checkbox" name="ids[]" value="<?php echo $user['user_id'];?>"></td>
<td><?php echo $id;?></td>
<td><?php echo $user['user_name'];?></td>
<td><?php echo $user['user_type'];?></td>
<td><?php echo $user['address'];?></td>
<td><?php echo $user['contact'];?></td>
<td><?php
if($user['status']==1)
{
echo "Active";
}
else
{
echo "InActive";
}
?></td>
<td><a href="edit.php?id=<?php echo base64_encode($user['user_id']);?>">Edit</a>
<a href="viewuser.php?id=<?php echo base64_encode($user['user_id']);?>">View</a>
<a href="delete.php?id=<?php echo base64_encode($user['user_id']);?>">Delete</a>
<a href="changepwdbyuser.php?id=<?php echo base64_encode($user['user_id']);?>">Change password</a>
</td>
</tr>
<?php
$id++;
}
?>
<tr>
<td>Status<select name="action">
<option value="1">Active</option>
<option value="0">Deactive</option>
<option value="del">Delete</option>
</select></td>
<td>
<input type="button" name="del" id="btn_tag" value="GO" onClick="submitform()"/>
</td>
<td><?php
?></td>
</tr>
</table>
</form>
when click on main checked box for all select then call onClick="selectAll(this)" function .
now
<script>
// for only checked all by js
function selectAll(source) {
checkboxes = document.getElementsByName('ids[]');
for(var i in checkboxes)
checkboxes[i].checked = source.checked;
}
</script>
then to sumit the form by javascript and post the value in action using onClick="submitform()"
function submitform()
{
document.myform.action='deleteform.php';
document.myform.submit();
}
Now where we use action like delete form.php by this page we can get the values
<?php
session_start();
error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE);
include 'init.php';
//print_r($_REQUEST['ids']);
//$_REQUEST['action'];
$ids = implode(',',$_REQUEST['ids']);
if($_REQUEST['action']=='del')
{
$user->DeleteByCheckbox($ids);
$_SESSION['msg']="Delete Successfully";
header('Location: manageuser.php');
}
if($_REQUEST['action']==0)
{
echo $act=$_REQUEST['action'];
$user->updatestatusBycheck($ids,$act);
$_SESSION['msg']="Deactivate Successfully";
header('Location: manageuser.php');
}
if($_REQUEST['action']==1)
{
$act=$_REQUEST['action'];
$user->updatestatusBycheck($ids,$act);
$_SESSION['msg']="Activate Successfully";
header('Location: manageuser.php');
}
?>
<form method="post" action="" name="myform">
<table width="100%">
<tr>
<th><input type="checkbox" id="selectall" onClick="selectAll(this)"></th>
<th>Id</th>
<th>Username</th>
<th>UserType</th>
<th>Address</th>
<th>Contact</th>
<th>Status</th>
<th>Action</th>
</tr>
<?php
$id= 1;
foreach($userlist as $user)
{
?>
<tr>
<td><input type="checkbox" name="ids[]" value="<?php echo $user['user_id'];?>"></td>
<td><?php echo $id;?></td>
<td><?php echo $user['user_name'];?></td>
<td><?php echo $user['user_type'];?></td>
<td><?php echo $user['address'];?></td>
<td><?php echo $user['contact'];?></td>
<td><?php
if($user['status']==1)
{
echo "Active";
}
else
{
echo "InActive";
}
?></td>
<td><a href="edit.php?id=<?php echo base64_encode($user['user_id']);?>">Edit</a>
<a href="viewuser.php?id=<?php echo base64_encode($user['user_id']);?>">View</a>
<a href="delete.php?id=<?php echo base64_encode($user['user_id']);?>">Delete</a>
<a href="changepwdbyuser.php?id=<?php echo base64_encode($user['user_id']);?>">Change password</a>
</td>
</tr>
<?php
$id++;
}
?>
<tr>
<td>Status<select name="action">
<option value="1">Active</option>
<option value="0">Deactive</option>
<option value="del">Delete</option>
</select></td>
<td>
<input type="button" name="del" id="btn_tag" value="GO" onClick="submitform()"/>
</td>
<td><?php
?></td>
</tr>
</table>
</form>
when click on main checked box for all select then call onClick="selectAll(this)" function .
now
<script>
// for only checked all by js
function selectAll(source) {
checkboxes = document.getElementsByName('ids[]');
for(var i in checkboxes)
checkboxes[i].checked = source.checked;
}
</script>
then to sumit the form by javascript and post the value in action using onClick="submitform()"
function submitform()
{
document.myform.action='deleteform.php';
document.myform.submit();
}
Now where we use action like delete form.php by this page we can get the values
<?php
session_start();
error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE);
include 'init.php';
//print_r($_REQUEST['ids']);
//$_REQUEST['action'];
$ids = implode(',',$_REQUEST['ids']);
if($_REQUEST['action']=='del')
{
$user->DeleteByCheckbox($ids);
$_SESSION['msg']="Delete Successfully";
header('Location: manageuser.php');
}
if($_REQUEST['action']==0)
{
echo $act=$_REQUEST['action'];
$user->updatestatusBycheck($ids,$act);
$_SESSION['msg']="Deactivate Successfully";
header('Location: manageuser.php');
}
if($_REQUEST['action']==1)
{
$act=$_REQUEST['action'];
$user->updatestatusBycheck($ids,$act);
$_SESSION['msg']="Activate Successfully";
header('Location: manageuser.php');
}
?>
EmoticonEmoticon