I'm currently developing a back office for some website, and I've come across some problems with file and information insert into databases. First I cannot upload a file and information in the same form without having to declare a variable for every other input, and second cannot append the declared object, like I always do, to the upload file form.
I've tried appending as and object but some of the inputs get undefined indexes.
This is the code i tried, to append an object to formData():
$(document).ready(function() {
$('#addinfo-form').submit(function(e) {
var info = {
'name':$('#name').val(),
'email':$('#email').val(),
'country':$('#country :selected').val()
}
var file = $('#file').prop('files')[0];
var new_info = new formData();
new_info.append('info', info);
new_info.append('file', file;
$.ajax({
type:'POST',
url:'add-info.php',
data:new_info,
dataType:'json',
processData:false,
contentType:false,
encode:true,
}
.done(function(data) {
})
.fail(function(data) {
});
e.preventDefault();
});
});
Expected outcome should send info to php file via json to then be processed and inserted in the database.
\nNotice: Undefined index: location in C:\\wamp64\\www\\dfrango\\administrator\\assets\\functions\\gallery\\add-gallery.php on line 10
\n{\"success\":false,\"errors\":{\"name\":\"Por favor preencha os campos obrigat\\u00f3rios.\"}}" – andrejmonteiro Aug 27 '19 at 19:21