terminal42 / contao-ajaxform

Submit a form through ajax and display error or confirmation message.
14 stars 7 forks source link

Ajaxform and input file #8

Closed chibko closed 7 years ago

chibko commented 8 years ago

Hello,

It seems that ajaxform doesn't handle input file. The form is send but the file is not stored in the selected folder. When input file is mandatory, the form i not send, i have a message saying that the file field can't be empty… Ajaxform 1.0.2 and Contao 3.5.12.

chibko commented 8 years ago

I have found a solution. In the templates folder, ajaxform.html5 i have replace

$.ajax({
                type: '<?php echo strtoupper($this->method); ?>',
                data: form.serialize(),
                cache: false,
                success: function(data) {

by

$.ajax({
                type: '<?php echo strtoupper($this->method); ?>',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function(data) {

Don't know if it's the best way, but works on firefox, chrome, safari and even IE9 ! This fix is for jquery layout…

aschempp commented 8 years ago

File uploads do not work in Ajax by default, especially not in all browsers. I think you should use a regular form if there are file uploads...

chibko commented 8 years ago

Yes i know, but in modern browsers it seems to work well and i was surprised that it works even on IE9. I will check on various browsers. Thanks Andreas.

qzminski commented 7 years ago

Just in addition to the code above the formData represents the FormData object. I see no reason to not incorporate this fix.

var formData = new FormData(this);
qzminski commented 7 years ago

Fixed in e32cb00.