Is it possible to add parameters to your php $_POST data through javascript before submitting the form without making individual hidden input tags?
I have a page that uses ajax (non-jQuery) which parses the innerText of <td>
elements and sends them to a php page for processing.
I'm now going to make a .csv file from that data (via the php page) and I can no longer do that via ajax. Therefore, I have to submit the whole form and leave the page. When doing this, I don't know how to add parameters to the $_POST data like I did with ajax. When the form is submitted, it only processes the input tags and I can't add my custom data like I did with the ajax call.
Thanks!
EDIT: Ajax code as requested by Matthew
function generateReport(saveReport)
{
xmlHttp=GetXmlHttpObject();
var params = [];
if(saveReport !== undefined)
{
params.push("reportName=" + document.myForm.reportName.value);
}
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var cols = document.myForm.colsUsedSel;
if(cols.options.length == 0)
{
alert("Please choose columns to view in the report.");
return;
}
//Loop through display columns
for(var i = 0; i < cols.options.length; i++)
{
params.push("displayCols[]=" + cols.options[i].value);
}
//Loop through <tr>'s of "where clause" table
var trList = document.getElementById("clauseTable").childNodes;
for(var x = 0; x < trList.length; x++)
{
var tdList = trList[x].childNodes;
for(var y = 0; y < tdList.length; y++)
{
var tdType = tdList[y].getAttribute("class");
//Check if there is a class for this <td>
if(!!tdType)
params.push(tdType + "=" + encodeURIComponent(tdList[y].innerText));
}
}
//Loop through <tr>'s of "order by" table
var trList = document.getElementById("orderByTable").childNodes;
for(var x = 0; x < trList.length; x++)
{
var tdList = trList[x].childNodes;
for(var y = 0; y < tdList.length; y++)
{
var tdType = tdList[y].getAttribute("class");
//Check if there is a class for this <td>
if(!!tdType)
params.push(tdType + "=" + encodeURIComponent(tdList[y].innerText));
}
}
if(document.myForm.generateCSV.checked)
params.push("generateCSV=1");
else
params.push("generateCSV=0");
params.push("sid="+Math.random());
xmlHttp.onreadystatechange= stateChangedGenerate;
xmlHttp.open("POST","reportBuilderDB.php",true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.send(params.join("&"));
}