I’m using the Contact Form plugin to submit a form that can also upload files via Ajax. The problem ist that instead of a success (200
) I get a status code of 302
. But I receive the resulting mail properly.
Everything worked fine when I hadn’t set everything up for the file upload. I serialized the form data, expected json, success (200
).
...
dataType: 'json',
data: $(this).serialize(),
...
But when I switched to this to enable receiving files, things went south (302
):
const formData = new FormData(this.form);
$.post({
url: '/index.php',
data: formData,
type: 'POST',
cache: false,
contentType: false,
processData: false,
success: response => {
if (response.success) {
this.showSuccess();
} else {
this.showError();
}
},
error: (xhr) => {
// FIXME: This is a workaround because for some reason Craft returns a 302, even though everything works
// fine. See stackoverflow question here and fix if there is a solution.
if (xhr.status === 302) {
this.showSuccess();
} else {
this.showError();
}
}
});
I’m on Craft 3.0.15 and set up SMTP in Settings -> EMail. I tried it locally (using MAMP) and on my hosted server. Both give me the 302
.
Any hint would be much appreciated.
Cheers, Mark