I’ve gone through a solution on processing checkboxes and think I understand what I need to do, but I have a problem where I put my delete button in this code. Here is my table:
<table>
<thead>
<tr>
<th>Camera Name</th>
<th>Date Created</th>
<th>Video Size</th>
<th>Video Length</th>
<th>
<button type="submit" class="deletebutton" name="delete_video" value="Delete" title="Delete the selected videos" onClick="return confirm('Are you sure you want to delete?')">Delete</button><br>
<input type="checkbox" name="radioselectall" title="Select All" />
</th>
</tr>
</thead>
<tbody>
<?php
for($i=0;$i<$num_videos;$i++)
{
//do stuff
//Note: I'm looping here to build the table from the server
?>
<tr >
<td onclick="DoNav('<?php echo $url; ?>');">
<?php echo $result_videos[$i]["camera_name"]; ?>
</td>
<td onclick="DoNav('<?php echo $url; ?>');">
<?php echo setlocalTime($result_videos[$i]["video_datetime"]); ?>
</td>
<td onclick="DoNav('<?php echo $url; ?>');">
<?php echo ByteSize($result_videos[$i]["video_size"]); ?>
</td>
<td onclick="DoNav('<?php echo $url; ?>');">
<?php echo strTime($result_videos[$i]["video_length"]); ?>
</td>
<td>
<form name="myform" action="<?php echo htmlentities($_SERVER['REQUEST_URI']); ?>" method="POST">
<input type="checkbox" name="radioselect" title="Mark this video for deletion"/>
<input type="hidden" name="video_name" value="<?php echo $result_videos[$i]["video_name"]; ?>" />
</form>
</td>
</tr>
...
Notice that I loop through and populate the table from the server but the header is not looping through obviously. I used to put the delete button in the form and on each line of the table. But now since I want multi-delete I create checkboxes on each line and put the delete button in the header. I should also note that video_name is crucial so I know what videos to delete.
But that is the problem, since I don’t have a submit (delete) in the form (that is in the loop) I can’t process theses checkboxes. Instead I only have the delete button Can anyone suggest a better way to do this?
The form should go around the whole table, and rather than have a hidden input for the name you can have it in the checkbox’s name:
Then, in your PHP script that receives the POST request,
$_POST['radioselect']will be an array. You can then use:This will loop through the selected checkboxes. You get the
video_namein$kand you can handle it as you would a single deletion.