How can I send a variable with formdata? I am sure it is really simple but I've tried some things and it is not working. I am using the blueimp fileupload plugin by the way.
My code now:
<script>
$(function () {
'use strict';
var url = window.location.hostname === 'site.nl/demo/server/php/' ?
'//site.nl/' : 'demo/server/php/';
$('#fileupload').fileupload({
url: url,
dataType: 'json',
formData: [
{ name: 'custom_dir', value: '/fileupload/<?PHP echo $_GET['bedrijf'] ?>/<?PHP echo $_GET['alias'] ?>/' },
{ name: 'cat_id', value: '<?PHP echo $gtc['id']; ?>'},
{ name: 'name', value: $( "#filename" ).val()},
],
add: function (e, data) {
data.context = $('<button/>').text('Uploaden starten').addClass('font-15 btn btn-secondary btn-lg waves-effect btnadd fullwidth')
.appendTo('.uploadbutton')
.click(function () {
data.submit();
});
},
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo('#files');
});
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .progress-bar').css(
'width',
progress + '%'
);
}
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
});
</script>
This is the part that is empty:
{ name: 'name', value: $( "#filename" ).val()},
The echoed php values work fine, but this one is empty.
I've also tried it this way:
var filename = $( "#filename" ).val();
And then below
{ name: 'name', value: filename},
This is my input field:
<input class="form-control" id="filename" type="text" name="filename" value="">
What am I doing wrong here?