junestag
10-03-2007, 05:34 PM
I've created dynamic fields using DHTML in my form page. But now I want to process those dynamic fields in my PHP form processing page and I'm unsure how to go about it.
I'm assuming some kind of for loop will allow me to go through my $_POST variables...?
Here's how I created the variables in my form page:
<script type="text/javascript">
x=0;
function insertRow(){
eLabel=document.createElement("label");
eLabel.setAttribute("id","label");
eLabel.setAttribute("for","DEPT"+x);
eDept=document.createElement("select");
eDept.setAttribute("id","dept"+x);
eDept.setAttribute("class","select");
eBR=document.createElement("br");
eBR2=document.createElement("br");
for (i=0; i < document.theForm.DEPT.length; i++) {
Option[i] = document.theForm.DEPT[i];
objOption = new Option(Option[i].text,Option[i].value);
eDept.options[eDept.length] = objOption;
}
document.getElementById("mContainer").appendChild(eLabel);
document.getElementById("mContainer").appendChild(eDept);
document.getElementById("mContainer").appendChild(eBR);
document.getElementById("mContainer").appendChild(eBR2);
x++;
}
</script>
So you see, the variables are named, in this example, 'dept' + the value of x in that iteration.
I guess what I'm asking is, how do you retrieve values from a form when you don't know how many values there will be ahead of time?
I'm assuming some kind of for loop will allow me to go through my $_POST variables...?
Here's how I created the variables in my form page:
<script type="text/javascript">
x=0;
function insertRow(){
eLabel=document.createElement("label");
eLabel.setAttribute("id","label");
eLabel.setAttribute("for","DEPT"+x);
eDept=document.createElement("select");
eDept.setAttribute("id","dept"+x);
eDept.setAttribute("class","select");
eBR=document.createElement("br");
eBR2=document.createElement("br");
for (i=0; i < document.theForm.DEPT.length; i++) {
Option[i] = document.theForm.DEPT[i];
objOption = new Option(Option[i].text,Option[i].value);
eDept.options[eDept.length] = objOption;
}
document.getElementById("mContainer").appendChild(eLabel);
document.getElementById("mContainer").appendChild(eDept);
document.getElementById("mContainer").appendChild(eBR);
document.getElementById("mContainer").appendChild(eBR2);
x++;
}
</script>
So you see, the variables are named, in this example, 'dept' + the value of x in that iteration.
I guess what I'm asking is, how do you retrieve values from a form when you don't know how many values there will be ahead of time?