0
It would have been possible to send some formularies at the same time with Formdata?
For example, each product will have sizes and images. It would have to separate each product into an array and send it at the same time to the PHP page, so I could walk through them with a foreach and register.
I tried that, but it mixes the data of all products, instead of separating:
var dados = new FormData();
$('.copiar-elemento').each(function() {
$(this).find("select[name*='tamanho']").each(function(index, element) {
dados.append('cores[tamanhos][]', element.value);
});
$(this).find('input:file').each(function(index, element) {
dados.append('cores[imagens][]', element.files[0]);
});
});
$.ajax({
url: $('#form-produto').attr('action'),
type: 'POST',
data: dados,
dataType: 'json',
processData: false,
contentType: false,
cache: false,
success: function(data) {
console.log(data);
}
});
Sorting doesn’t matter, since your PHP processing will reorganize, as the name of each POST, the array.
– Lollipop
The only important factor is to know if the data is being sent correctly, according to each name, in the output.
– Lollipop
Has a photo/print of request, with the information generated?
– Lollipop
I put the print on the question. Do you know where you have the "GG" and "M"? GG belongs to one product and M belongs to another. I have to create a "colors" index for each product.
– Diego Vieira
Note: The "title" will be the same for all products, so do not need to stay within the "colors", this part is correct.
– Diego Vieira
The problem is that it is creating only one "color" and putting all the data inside this, instead of separating.
– Diego Vieira
The problem is in your logic. Once you create a name request, it is unique. You should do something like: cores_images and cores_sizes to be able to specify better.
– Lollipop
Adding images and sizes is correct, the problem is to separate products. It had to generate something in this style: colors ['images' => ['imagem1', 'imagem2'], 'sizes' => [’m', 'G']], colors ['images' => ['imagem3', 'imagem4'], 'sizes' => ['P', 'GG']]
– Diego Vieira
So knife: 'colors[images][ '+index+' ]'
– Lollipop
Man, that’s right. Thanks for the help!
– Diego Vieira
I will post the reply, mark as completed.
– Lollipop