Ok, I'm going nuts with this problem:
I have a form with some hidden fields and a file upload field. Because I have other form tags on my page, I'm submitting it using a tag and ajax.
Here's my html code:
<form id="formdoc" name="formdoc" enctype="multipart/form-data" class="form">
<table class="table table-bordered rounded">
<thead>
<tr>
<th scope="col">Tipo de documento</th>
<th scope="col">Status</th>
<th scope="col">Arquivo</th>
<th scope="col">Ação</th>
</tr>
</thead>
<tbody>
<tr>
<td>RG, CPF ou RNE</td>
<td>
<span class="<?php echo $classPessoal; ?> docpessoal">
<?php if($btPessoal==''){ echo 'Pendente';}else{ echo 'Arquivo Enviado';} ?>
</span>
</td>
<td>
<div class="custom-file">
<input type="file" name="upload[]" class="custom-file-input" id="docpessoal" multiple <?php echo $btPessoal; ?>>
<label class="custom-file-label" for="customFile">Selecionar documento...</label>
</div>
</td>
<td>
<input type="hidden" name="id_imovel" value="<?php echo $_GET['idimv']; ?>">
<input type="hidden" name="tipo_doc" value="pessoal">
<button type="button" id="enviardoc" class="btn btn-primary font-weight-bolder" <?php echo $btPessoal; ?>>
<i class="ki ki-check icon-sm"></i>
Enviar
</button>
</td>
</tr>
</tbody>
</table>
</form>
This is my Ajax Call:
$("#enviardoc").click(function(e){
e.preventDefault();
var formData = new FormData($("#formdoc")[0]);
$.ajax({
type: 'POST',
url: 'post_doc.php',
data: formData,
dataType: 'json',
contentType: false,
cache: false,
processData:false,
beforeSend: function(){
//console.log(formData);
},
success: function(response){
if(response.status == 1){
alert("Sucesso!", ""+response.message+"", "success");
console.log(response);
}else{
alert("Erro!", ""+response.message+"", "error");
console.log(response);
}
}
});
});
No matter what I do, it doesn't submit anything to my PHP page. I double checked and my PHP is returning the right value of all fields.
It looks like var formData
is always empty!