Fordata picking up empty form

Asked

Viewed 15 times

1

Good evening. I am trying to get the files via formData but an empty form is coming.

Follows the codes:

<form action="<?=base_url()?>clientes/addNewFile" id="form_addNewImage" enctype="multipart/form-data" method="POST">
<div class="row">   
    <div class="col-md-12">
        <span class="btn btn-primary btn-file">
            <span class="fileinput-new"><i class="material-icons">add</i> Adicionar Imagens</span>
            <input type="file" id="cliente_fotos" name="cliente_fotos[]" multiple>
            <input type="hidden" name="idCliente" value="<?=$cliente->idCliente?>">      
            <input type="hidden" name="cliente_Cpf" value="<?=$cliente->cliente_cpf?>">       
            <input type="hidden" name="clienteFotos" value="<?=$cliente->cliente_fotos?>">
            <input type="hidden" name="type" value="img">
        </span>
    </div>      
    <div class="col-md-12 mt-3">
        <div class="row" id="image_view"></div>                                
    </div>  
    <div class="col-md-12 mt-3">
        <div class="row" id="image_preview"></div>                                
    </div>
    <div class="col-md-12 mt-3">
        <button type="submit" class="btn btn-primary" data-loading-text="<i class='fa fa-spinner fa-spin '></i> Salvando"><i class="fa fa-floppy-o"></i> Salvar</button>                            
    </div>      
</div>

    $('#form_addNewImage').on('submit', function(e)
    { 
      e.preventDefault();
      var data = new FormData(this);
    });
  • Where are you checking that it is empty? You will use Ajax?

  • I will use ajax yes. I checked that it is empty via console.log(date);

  • The console does not show Formdata content, but the form arrives at the normal destination.

  • Ta blz friend. I will test. Thank you

1 answer

0


It is not empty. It turns out that the console does not display the values. You can check the Formdata data in the console by converting it to array:

$('#form_addNewImage').on('submit', function(e) { 
   e.preventDefault();
   var data = new FormData(this);
   console.log(Array.from(data));
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.