File Upload
Please follow this instructions to implement the file upload functionality
If you want to add this kind of field to your form, you'll need to modify the code sending script.
<input type="file" name="file">
Imagine you have an ajax code witch looks like this one:
$("#my-form").submit(function() {
const $form = $(this);
let options = {
type: 'POST',
url: _dynamic_base + '/lead/' + window.websiteID,
data: $form.serialize(),
};
$.ajax(options)
.then(function(data) {
console.log("data", data)
})
});
In the case where the user uploaded files, you'll need to add them to the form data. To do that, please add some code to the ajax script:
$("#my-form").submit(function() {
const $form = $(this);
let hasFiles = 0;
let $fileInputs = $(this).find('input[type="file"]');
let options = {
type: 'POST',
url: _dynamic_base + '/lead/' + window.websiteID,
data: $form.serialize(),
};
$fileInputs.each(function(index) {
if(this.files.length) return hasFiles = 1;
});
if(hasFiles) {
options.data = new FormData($form[0]);
options.cache = false;
options.contentType = false;
options.processData = false;
}
$.ajax(options)
.then(function(data) {
console.log("data", data)
})
});
Last updated