this first question on s.o apologies if done incorrectly i'm stumped whether possible let alone how it. have form , within form dynamically generated table. user adds defects table if still outstanding. amount of rows vary every use.
<table class="mytable" id="open-defect-table" name="open-defect-table"> <tr> <th name="example">defect id</th> <th>status</th> <th>severity</th> <th>priority</th> <th>assigned to</th> <th>defect link</th> <th>summary</th> <th>comments</th> </tr> </table>
above table sits on page , whenever user clicks button:
<input type="button" name="open-defect-add-button" id="open-defect-add-button" value="add" onclick="addopendefect()">
it adds details table , provides unique id row.
however i'm not sure how go posting on form submit page..in case "export.php"
within php page this:
<h2>open defects: <span> <?php $selected_option = $_post["open-defects-select"]; if ($selected_option == "yes"){ // i'm trying work out } else { echo ("none"); } ?></span></h2>
within field want copy table created within previous form.
is possible? , if how go or best way in tackling this?
any appreciated , again apologies if missing details.
you can give name each cell on table, example, if have table names , phones, cells in column "name" share name "name", , cells in column "phone" share name "phone". notice cells share same names, when happens, become array, so, have array of names , array of phones. example code:
zzz.html
<html> <head> <script type="text/javascript"> function add_row () { var tbl = document.getelementbyid( "tbl" ); var row = tbl.insertrow( -1 ); // insert row @ end of table. var cel = row.insertcell( -1 ); // insert cell @ end of row. cel.innerhtml = "<input type='text' name='name[]'/>"; // ◄■■■ [] array. cel = row.insertcell( -1 ); // reusing same variable. cel.innerhtml = "<input type='text' name='phone[]'/>"; // ◄■■■ [] array. } </script> </head> <body> <button onclick="add_row()">add row</button> <form method="post" action="zzz.php"> <table id="tbl" border="1"> <tr> <td>name</td> <td>phone</td> </tr> </table> <input type="submit" value="submit"/> </form> </body> </html>
zzz.php
<?php if ( isset( $_post["name"] ) && isset( $_post["phone"] ) ) { echo "names: <br/>"; foreach ( $_post["name"] $name ) // $_post["name"] array. echo $name . "<br/>"; echo "<br/><br/>" . "phones: <br/>"; foreach ( $_post["phone"] $phone ) // $_post["phone"] array. echo $phone . "<br/>"; } else echo "error: no data"; ?>
copy-paste previous codes in files given names (zzz.html, zzz.php), open zzz.html in browser. click several times button "add row", type data, click "submit". php names , phones arrays , display contents.
the important thing here use of []
:
cel.innerhtml = "<input type='text' name='name[]'/>"; // ◄■■■ [] array.
all <input
s named "name[]" become array , submitted array.
the idea send whole table arrays, 1 array per column. on php side, getting table's data arrays, able re-build entire table again.
Comments
Post a Comment