I have the following HTML table, each row of which is generated from data in a MySQL table via the Smarty template engine.
The 1st column consists of checkboxes which I want to use to select multiple rows for deletion. The last column is a submit button (form) to view further details of that entry.
I'm having trouble figuring out the how to post all the checkbox selected rows for processing.
GENERATED TABLE:
{foreach from=$data item=field}
<tr>
<td><input type="checkbox" name="checklist[]" value="{$field.id}" /></td>
<td style="text-align:center">{$field.id}</td>
<td style="text-align:center">{$field.domain}</td>
<td style="text-align:center">{$field.email}</td>
<td style="text-align:center">{$field.keysize}-bit</td>
<td style="text-align:center">{$field.keyalg}</td>
<td style="text-align:center">{$field.hashalg}</td>
<td style="text-align:center">{$field.organization}</td>
<td style="text-align:center">{$field.timestamp}</td>
<td style="text-align:center"><form id="view" method="post" action="view.php"><input type="hidden" name="id" value="{$field.id}" /><button type="submit" name="submit">View</button></form></td>
</tr>
{/foreach}
I've had a look at some examlpes on here that utilize jQuery but am not 100% on how I'd implement them. in this instance. Also had a look at this: Get $_POST from multiple checkboxes. But I cant wrap the first column in a <form>
tag as it gets repeated by my foreach
function producing a submit button for each record.
What I'm trying to achieve is to place a button (outside the table) that'll post the selected checkboxes field.id
as an array for deletion by my delete_records.php
file. Similar to this Checkbox inside a php foreach loop to delete whatever is checked. However I already have a form element on each row already.
I feel like I'm missing some obvious way to achieve my goal, so any help appreciated.