I’m trying to build a simple HTML table form that displays values from a PHP array. The display part is easy, but I forget how to code form mechanics like selecting and deletion of these values based on user input. I figured they may be an example of something similar online, but have not found anything suitable so far. I am interested in some simple code that allows a user to delete single or multiple lines from a HTML table. I would like to avoid JavaScript or jQuery if possible.
Here is what I have so far:
HTML/ PHP
<form action="options.php" method="post">
<table>
<thead>
<tr>
<th><input type="checkbox"></th>
<th>Domain Name</th>
</tr>
</thead>
<tfoot>
<tr>
<th><input type="checkbox"></th>
<th>Domain Name</th>
</tr>
</tfoot>
<tbody>
<?php
foreach ( $my_domains as &$value ) {
echo '<tr><td><input type="checkbox"></td><td>'.$value['domain'].'</td></tr>';
}
?>
</tbody>
</table>
</form>
PHP ARRAY
Array ( [10] => Array ( [domain] => dsdssd.com ) [11] => Array ( [domain] => google.com ) [12] => Array ( [domain] => new.com ) [13] => Array ( [domain] => blah.com ) )
So.. In a nutshell. This is what you asked for.. Anyways, you add more options in the form on checkboxex, like which domains are active and so on.. Still, if I was you, I would make this in jQuery and with ajax. Would be much more neater.
Example: http://kopli.pri.ee/stackoverflow/6829783.php
NOTE There is no memory. So if basically reload the page in any way, some parts will be reseted.
EDIT
This one has the delete all function. It actually uses php fallback aswell as jQuery script to select all. Not sure if its the ultimate way of doing things, so you might want to remove the php fallback option, if your going to use jQuery select all.
Example 2: http://kopli.pri.ee/stackoverflow/6829783_v2.php
(This is the updated code below)