no, allora, per passare dei parametri tramite una richiesta POST a partire da una form, devi usare gli input (ed i select ed i textarea) cioè gli elementi studiati per l'inserimento di dati da parte dell'utente, dati che vengono poi inviati alle pagine dinamiche (PHP nel tuo caso) e letti come hai scritto tu (anche se devi usare il nome dell'elemento e non l'id).
Secondo me, fai prima a modificare la procedura che genera la table, per introdurre nei diversi TD anche un input ti tipo hidden (quindi non visualizzato) con il valore corrispondente.
Ad esempio, devi ottenere alla fine:
Codice PHP:
<form action="..." method = "POST">
<table>
<tr>
<td>Valore 1<input type="hidden" name="tabella[0][0]" value ="Valore 1" /></td>
<td>Valore 2<input type="hidden" name="tabella[0][1]" value ="Valore 2" /></td>
<td>Valore 3<input type="hidden" name="tabella[0][2]" value ="Valore 3" /></td>
<td>Valore 4<input type="hidden" name="tabella[0][3]" value ="Valore 4" /></td>
</tr>
<tr>
<td>Valore 5<input type="hidden" name="tabella[1][0]" value ="Valore 5" /></td>
<td>Valore 6<input type="hidden" name="tabella[1][1]" value ="Valore 6" /></td>
<td>Valore 7<input type="hidden" name="tabella[1][2]" value ="Valore 7" /></td>
<td>Valore 8<input type="hidden" name="tabella[1][3]" value ="Valore 8" /></td>
</tr>
<tr>
<td>Valore 9<input type="hidden" name="tabella[2][0]" value ="Valore 9" /></td>
<td>Valore 10<input type="hidden" name="tabella[2][1]" value ="Valore 10" /></td>
<td>Valore 11<input type="hidden" name="tabella[2][2]" value ="Valore 11" /></td>
<td>Valore 12<input type="hidden" name="tabella[2][3]" value ="Valore 12" /></td>
</tr>
</table>
</form>
Quando invierai la form dal PHP otterrai i dati:
Codice PHP:
$dati = $_POST["tabella"];
echo $dati[0][2]; //Stampi: Valore 3
echo $dati[2][0]; //Stampi: Valore 9
e così via.
Se invece non hai modo di modificare il contenuto dell'HTML, lo puoi fare in JS, ma secondo me è molto più semplice nel medoto sopracitato.
Comunque, l'idea è la stessa: metti di avere la tabella ed un sistema per identificare le celle
Codice PHP:
<form id="MyForm" action = "..." method = "POST">
<table id = "MyTable">
<tr>
<td>Valore da prendere</td>
<td>Valore da prendere 2</td>
<td>Valore da prendere 3</td>
<td>Valore da prendere Reloaded</td>
<td>Valore da prendere Ultimate</td>
</tr>
<tr>
<td>Valore da prendere Last chance</td>
<td>Valore da prendere hohoho</td>
<td>Valore da prendere ...</td>
<td>Valore da prendere mi sono stufato</td>
<td>Valore da prendere</td>
</tr>
<tr>
<td>Valore da prendere</td>
<td>Valore da prendere</td>
<td>Valore da prendere</td>
<td>Valore da prendere</td>
<td>Valore da prendere</td>
</tr>
</table>
</form>
a questo punto fai una funzione che esamini la tabella ed inserisca gli input hidden nella form.
Codice PHP:
//Viene dato questo nome agli input
var generalName = "tabella";
var CreateInput = function(name, value){
var tmp = document.createElement("input");
tmp.value = value;
tmp.name = name;
tmp.type = "HIDDEN";
return tmp;
}
//Questo accetta come argomento il tbody della tabella
var WalkThroughTable = function(tbody){
var child;
var index = 0;
var inputs = [];
for(child = tbody.firstChild; child != null; child = child.nextSibling){
if(child.nodeType == 1){
if(child.tagName.toUpperCase() == "TR"){ //È un TR
inputs = inputs.concat(WalkThroughRow(child, index++));
}
}
}
return inputs;
}
var WalkThroughRow = function(row, indexRow){
var child;
var inputs = []; //Array per il ritorno
var index = 0;
for(child = row.firstChild; child != null; child = child.nextSibling){
if(child.nodeType == 1){ //È un Element
if(child.tagName.toUpperCase() == "TD"){ //È un TD
inputs.push(Td2Input(child, indexRow, index++));
}
}
}
return inputs;
}
var Td2Input = function(td, indexRow, indexCell){
var value = td.innerHTML;
var name = generalName+"["+indexRow+"]["+indexCell+"]";
return CreateInput(name, value);
}
//Chiamata Generale
var ExtractValueFromCell = function(tableID, formElem){
if(!tableID) throw "l'id della tabella non può essere vuoto";
var table = document.getElementById(tableID);
var tbody = null;
for(tbody = table.firstChild; tbody != null; tbody = tbody.nextSibling){
if(tbody.nodeType == 1){//È un elemento
if(tbody.tagName.toUpperCase() == "TBODY") break;
}
}
var inputs = WalkThroughTable(tbody);
for(var i = 0; i < inputs.length; i++){
var inpt = inputs[i];
formElem.appendChild(inpt);
}
return true;
}
//Questa chiamata la metto come evento onSubmit della form
window.onload = function(){
document.getElementById("MyForm").onsubmit = function(){
ExtractValueFromCell("MyTable", this);
};
};
Mi sembra vada, ma non l'ho provato molto