0
I have a form that creates a list of selected images before sending through an input type='file'
However how can I pass the Array
Javascript to the form and submit it by clicking on action
?
I need to rescue the array sent in php in php itself
var nomess = [];
function handleFileSelect() {
var output = document.getElementById("resultt");
arquivos = $("#imagem").prop("files");
var nomes = $.map(arquivos, function(val) { return val.name; });
//new
var filesStr = "";
for (let i = 0; i < arquivos.length; i++) {
var extensao = nomes[i].split('.').pop().toLowerCase();
if(extensao == "doc" || extensao == "docx"){
icone = "http://www.programari.com.br/assets/images/icons/word.png";
}else if(extensao == "jpg" || extensao == "jpeg"){
icone = "http://www.programari.com.br/assets/images/icons/jpg.png";
}else if(extensao == "png"){
icone = "http://www.programari.com.br/assets/images/icons/png.png";
}else if(extensao == "xml"){
icone = "http://www.programari.com.br/assets/images/icons/xml.png";
}else if(extensao == "gif"){
icone = "http://www.programari.com.br/assets/images/icons/gif.png";
}else if(extensao == "pdf"){
icone = "http://www.programari.com.br/assets/images/icons/pdf.png";
}else if(extensao == "bmp"){
icone = "http://www.programari.com.br/assets/images/icons/bmp.png";
}else if(extensao == "txt"){
icone = "http://www.programari.com.br/assets/images/icons/txt.png";
}else if(extensao == "xlsx" || extensao == "xls"){
icone = "http://www.programari.com.br/assets/images/icons/xls.png";
}else{
icone = "http://www.programari.com.br/assets/images/icons/file.png";
}
nomess.push(arquivos[i]);
filesStr += "<li>" + arquivos[i].name + "<button onclick='removeLiy(this)' style='background-color:white; border:0'><i class='fas fa-trash' style='color:red; font-size: 24px; padding: 8px 0px 0px 3px;'></i></button><img src='"+icone+"' height='24' />" + "</li>";
}
console.log(nomess);
document.getElementById("imagem").value = "";
document.getElementById("resultt").innerHTML += filesStr;
}
function removeLiy(e) {
nomess = nomess.filter(function(imagem) {
return imagem.name !== e.parentNode.innerHTML.split("<button")[0];
console.log(nomess);
})
e.parentNode.parentNode.removeChild(e.parentNode);
console.log(nomess);
}
document.getElementById('imagem').addEventListener('change', handleFileSelect, true);
<form id="formExemplo" action="nova-acao/salvar'" method="post" enctype="multipart/form-data" data-toggle="validator" role="form">
<div class="col-md-4 form-group">
<input type="file" onchange="handleFileSelect" name="imagem" id="imagem" style="" multiple="multiple">
</div>
</form>
You just want to send input file values to the page that receives PHP or exactly want to pass in js to send?
– ElvisP
i wanted to take the js array and somehow create or populate an input file, soon after when I click submit it should send the other fields and this with the arrays. these arrays are images with no extension restriction...
– Richard Barcelos
@Eliseu B. you know how it should be done?
– Richard Barcelos
sorry for the delay, the solution below meets your need, if it works please give the vote of reply accepted.
– ElvisP