Form variables into a PHP array from DOM
Posted: Sat Mar 10, 2007 1:52 am
Hi All,
Is there an elegant way to these dom/html values into a php array to add them to a database?
So far I have only managed to echo them all. There is likely to be an unditermind amount of rows.
I know how to do this if PHP was creating the HTML code but not with DOM creating it.
Any pointers or ideas?
ta, Will./
Is there an elegant way to these dom/html values into a php array to add them to a database?
So far I have only managed to echo them all. There is likely to be an unditermind amount of rows.
I know how to do this if PHP was creating the HTML code but not with DOM creating it.
Any pointers or ideas?
ta, Will./
Code: Select all
if(isset($_POST['commented'])) {
// Get all posted variables!
foreach ($_POST as $var => $value) {
$var = ereg_replace("[^A-Za-z]", "", $var);
echo "$var = $value<br>\n";
}
for ($i = 0; $i < "driverType"; $i++) {
echo "Yup";
}
} else {
?>
<script type="text/javascript"> <!--//
var TDCount = 0;
function makeRow() {
TDCount++;
mypara=document.getElementById("paraID");
myselect = document.createElement("select");
myselect.setAttribute("name","driverType" + (TDCount));
myinput = document.createElement("input");
myinput.setAttribute("name","rowcount" + (TDCount));
myinput.setAttribute("value","rowcount" + (TDCount));
myinput.setAttribute("type","hidden");
//first option
theOption=document.createElement("option");
theText=document.createTextNode("--Select--");
theOption.appendChild(theText);
myselect.appendChild(theOption);
// First option
theOption=document.createElement("option");
theText=document.createTextNode("Deliver");
theOption.appendChild(theText);
theOption.setAttribute("value","delivery");
myselect.appendChild(theOption);
// Second option
theOption=document.createElement("option");
theText=document.createTextNode("Return");
theOption.appendChild(theText);
theOption.setAttribute("value","return");
myselect.appendChild(theOption);
//now the select has the options added with their text, values
mypara.appendChild(myselect);
mypara.appendChild(myinput);
} //-->
</script>
<?php
echo "<body onload=\"makeRow()\">";
echo "<form id=\"driverSummary\" name=\"driverSummary\" method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n";
echo "<input type=\"hidden\" name=\"commented\" value=\"set\">\n";
echo "<table>";
echo "<tr><td valign=bottom><div id=\"paraID\"></div></td></tr>\n";
echo "</table>";
echo "<br><br><br><input type=\"button\" value=\"Create Form\" onclick=\"makeRow()\" /><input type='reset' class='btn' value='Reset'><input type='submit' class='btn' value='Submit'></form>";
echo "</form>";
}