Sorry for the bad English, I'm still learning...
Well i have in HTML a table with only
<tr id="linha_1">
<td><input type="text" name="nome_cor[]" value="" /></td>
<td><input type="text" name="cod_cor[]" value="" /></td>
<td><input type="file" name="img_cor[]" /></td>
<td><input type="button" value="Remover" id="remove" onclick="$.removeLinha(this);" /></td>
</tr>
I also have a JS script that adds new rows to this table, this script copy the first line, so the user can add more colors...
$(document).ready(function()
{
var row_limit = 0;
$('#add').click(function()
{
var linha_total = $('tbody#repetir tr').length;
if (row_limit == 0 || row_limit > linha_total)
{
var linha = $('tbody#repetir tr').html();
var linha_total = $('tbody#repetir tr').length;
var linha_id = $('tbody#repetir tr').attr('id');
$('tbody#repetir').append('<tr id="linha_' + (linha_total + 1) + '">' + linha + '</tr>');
}
else
{
alert("Desculpe, mas você só pode adicionar até " + limite_linhas + " linhas!");
}
});
Using malsup form plugin to send the data via post:
$("#send").click(function(event) {
event.preventDefault();
$("#form-tapete").ajaxForm({
// validation and progress bar (*not important to the question i think*)
},
url: 'dados-tapete.php',
resetForm: false
}).submit();
I'm trying to read this in PHP with this code:
for ($i=0; $i < sizeof($cod_cor); $i++)
{
$path_cor = "catalogo/tapete/cor/";
$path_cor = $path_cor.basename($_FILES["img_cor"]["name"][$i]);
if (!move_uploaded_file($_FILES["img_cor"]["tmp_name"][$i], $path_cor))
die("Ocorreu um erro ao enviar a imagem, tente novamente!");
$cor_img_name = "catalogo/tapete/cor/".$_FILES["img_cor"]["name"][$i];
$cadastra_cores = $con->sql_query("INSERT INTO tape_cores VALUES ('$nome_tapete','$cod_cor[$i]','$nome_cor[$i]','$path_cor')");
}
The PHP script can read and send the values to the database, but only the first value... The rows that was added dynamically don't appear in the $_POST array...
I searched for this and found some asked questions here, but no solution...
Sorry for the bad English again, if you don't understand me I can try to explain in other words... thanks
sizeof($cod_cor)here?