I have a Javascript function to pass an array of data to a PHP file. My Javascript creates a form on the fly as follows
function SaveFileToDisk(filename)
{
var ssForm = document.createElement("form");
ssForm.method="post" ;
ssForm.action = "saveScenario.php" ;
ssForm.target = "hiddenSaveScenarioStatusFrame";
for (var i = 0; i < ScriptSteps.length; i++)
{
var ssInput = document.createElement("input");
ssInput.setAttribute("filename", filename);
ssInput.setAttribute("timestamp", ScriptSteps[i].timestamp);
ssInput.setAttribute("lhsName", ScriptSteps[i].lhsName);
ssInput.setAttribute("lhsPort", ScriptSteps[i].lhsPort);
ssInput.setAttribute("lhsBandwidth", ScriptSteps[i].lhsBandwidth);
ssInput.setAttribute("lhsDelayMin", ScriptSteps[i].lhsDelayMin);
ssInput.setAttribute("lhsDelayMax", ScriptSteps[i].lhsDelayMax);
ssInput.setAttribute("lhsDropLoss", ScriptSteps[i].lhsDropLoss);
ssInput.setAttribute("lhsFilters", ScriptSteps[i].lhsFilters);
ssInput.setAttribute("lhsDefaultFilter", ScriptSteps[i].lhsDefaultFilter);
ssInput.setAttribute("rhsName", ScriptSteps[i].rhsName);
ssInput.setAttribute("rhsPort", ScriptSteps[i].rhsPort);
ssInput.setAttribute("rhsBandwidth", ScriptSteps[i].rhsBandwidth);
ssInput.setAttribute("rhsDelayMin", ScriptSteps[i].rhsDelayMin);
ssInput.setAttribute("rhsDelayMax", ScriptSteps[i].rhsDelayMax);
ssInput.setAttribute("rhsDropLoss", ScriptSteps[i].rhsDropLoss);
ssInput.setAttribute("rhsFilters", ScriptSteps[i].rhsFilters);
ssInput.setAttribute("rhsDefaultFilter", ScriptSteps[i].rhsDefaultFilter);
ssForm.appendChild(ssInput) ;
}
document.body.appendChild(ssForm) ;
ssForm.submit() ;
document.body.removeChild(ssForm) ;
}
But when I write my PHP script I was expecting to find the array in the $_POST variable and thought that I would get each element of the array containing the above fields and corresponding data. When I look at the size of the $_POST array in the PHP script it comes out as zero. What am I doing wrong or am I using the wrong method for doing this sort of thing.
As an aside, I really only need to pass the filename over once but thought the easiest way was to pass it over with every element of the array. Is there a better way so that the filename is passed once and the remaining fields passed for each "step"? Have trawled the web for ideas on passing arrays of data from Javascript to PHP - there seem to be so many ways, one of them being the way I have tried, but does not explain retrieving the data on the PHP side.
thanks in advance
Andy