0

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.

Community
  • 1
  • 1
Elijah Paul
  • 281
  • 4
  • 22
  • What templating engine is this? because `{$field.id}` and the like are NOT valid php variables. – Marc B Jul 07 '14 at 19:26
  • Sorry, I forgot to mention, it's WHMCS. Will update the question. – Elijah Paul Jul 07 '14 at 19:27
  • it seems to me that the template is smarty ?? no ? – Leo Bali Jul 07 '14 at 19:35
  • Yes. Sorry. WHMCS uses the smarty template engine. I guess I should state that instead of WHMCS. – Elijah Paul Jul 07 '14 at 19:36
  • well, regardless of the templating engine, once it reaches the client, it's just html. what does the generated html look like, and what does $_POST look like when the form's submitted? the template only applies when the page is generated, and has absolutely nothing to do with the form being submitted back to the server. – Marc B Jul 07 '14 at 20:16
  • The html is just a regular table once generated. each row having a checkbox in column one. Posting the checkbox values is the problem I'm having, I'm not sure how to go about extracting the checkbox values in order to POST them back to the server. Primarily because each row also has a form in the last column, so I can't wrap the whole table in form tags, due to not being able to nest form tags. Hope that makes sense. – Elijah Paul Jul 07 '14 at 20:36

0 Answers0