I have 3 forms on the same page, where each form has inputs of the file type. I need to click on a single button, it is possible to correctly use Ajax to forward all fields (mainly that $ _FILES is available in the PHP page).
I've tried the following:
$('#cadastrar-emp').on('click', function () {
var form = $('#formCadEmp')[0],
formII = $('#formConfNFe')[0],
formIII = $('#formConfEmail')[0];
var data = new FormData(form),
dataII = new FormData(formII),
dataIII = new FormData(formIII);
data.append('formConfNFe', JSON.stringify(dataII));
data.append('formConfEmail', JSON.stringify(dataIII));
jQuery.ajax({
url: "actions/cadastrar-empresa.php",
type: 'post',
enctype: 'multipart/form-data',
cache: false,
contentType: false,
processData: false,
data: data,
success: function (data) {}
});
});
And I got the PHP page:
Array
(
[razao-social] =>
[nome-fantasia] =>
[cnpj] =>
[estado] =>
[cep] =>
[cidade] =>
[logradouro] =>
[bairro] =>
[complemento] =>
[numero] =>
[email] =>
[celular] =>
[fixo] =>
[insc-estadual] =>
[insc-municipal] =>
[cnae-fiscal] =>
[reg-trib] => 1
[formConfNFe] => {}
[formConfEmail] => {}
)
Being that way, I can not access the properties of array file
.