In realtà ho il problema con un modulo a ogni riga di una tabella, con javascript (in realtà jquery):
come Lothre1 ha detto, "alcuni browser nel processo di rappresentazione si chiuderà tag form a destra dopo il dichiarazione lasciando ingressi esterno dell'elemento"
che rende i miei campi di ingresso al di fuori della forma, quindi non posso accedere i figli della mia forma attraverso il DOM e JavaScript ..
tipicamente, il seguente codice di won jQuery funziona:
$('#id_form :input').each(function(){/*action*/});
// this is supposed to select all inputS
// within the form that has an id ='id_form'
ma quanto sopra exemple non funziona con il rendering HTML:
<table>
<form id="id_form"></form>
<tr id="tr_id">
<td><input type="text"/></td>
<td><input type="submit"/></td>
</tr>
</table>
sto ancora cercando una soluzione pulita (anche se con il TR 'id' parametro di percorrere il DOM sarebbe risolvere il problema problema specifico)
soluzione sporca sarebbe (per jQuery):
$('#tr_id :input').each(function(){/*action*/});
// this will select all the inputS
// fields within the TR with the id='tr_id'
quanto sopra exemple funziona, ma non è davvero "pulito", perché si riferisce alla inste TR ANNUNCIO DEL MODULO, e richiede AJAX ...
EDIT: processo completo con jQuery/ajax sarebbero:
//init data string
// the dummy init value (1=1)is just here
// to avoid dealing with trailing &
// and should not be implemented
// (though it works)
var data_str = '1=1';
// for each input in the TR
$('#tr_id :input').each(function(){
//retrieve field name and value from the DOM
var field = $(this).attr('name');
var value = $(this).val();
//iterate the string to pass the datas
// so in the end it will render s/g like
// "1=1&field1_name=value1&field2_name=value2"...
data_str += '&' + field + '=' + value;
});
//Sendind fields datawith ajax
// to be treated
$.ajax({
type:"POST",
url: "target_for_the_form_treatment",
data:data_string,
success:function(msg){
/*actions on success of the request*/
});
});
in questo modo, il "target_for_the_form_treatment" dovrebbe ricevere i dati POST come se una forma era inviato a lui (appart dal post [1] = 1, ma per implementare questa soluzione vorrei raccomandare di trattare con il file finale "&" di data_str invece).
ancora non mi piace questa soluzione, ma sono costretto a utilizzare la struttura delle tabelle a causa del DataTables plugin jQuery ...
Avvolgere l'intera tabella in un tag form (e inviare l'intero oggetto) o trasformare la tabella HTML in una tabella * come * struttura dove ogni "riga" è un modulo. Vedi qui: http://stackoverflow.com/a/15600151/1038812 – Matthew
Vedere la risposta di Alexx Roche. Penso che la sua dovrebbe essere la risposta accettata. La sua risposta risolve davvero il problema. –
La risposta di Alexx Roche non era la migliore nel mio caso, sto effettivamente visualizzando informazioni tabulari. – adg