0
I have 3 forms on the same page, where each form has inputs of the file type. I need that when clicking a single button, it is possible to forward, using Ajax, correctly all fields (mainly that $_FILES is available in the PHP page).
I 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) {}
    });
});
I got it from 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] => {}
)
And that way, I can’t access the properties of array file.
Hello @Brunofoller:
Uncaught TypeError: Cannot read property '0' of undefined.– lucasbento
Apologizing.
$('#formCadEmp').prop('files')[0];is the id of the field that receives the file.– Bruno Folle