Forms with enctype set as multipart/form-data get submited with the default application/x-www-form-urlencoded #168

Closed
opened 2018-06-22 10:52:25 -05:00 by davidSocast · 3 comments
davidSocast commented 2018-06-22 10:52:25 -05:00 (Migrated from github.com)

Hi guys, i've been struggling with something that i believe is a bug on this excellent library:

From the previous threads and the documentation, my understanding was that forms submitted through pjax are submitted with a content type set to "application/x-www-form-urlencoded".

However, if the form has a enctype set to "multipart/form-data", the pjax call is supposed to use this value and set the header Content-Type to this value.

I can't make it work on my server (Apache/PHP7) and despite the required enctype my data are sent as "application/x-www-form-urlencoded".

the formData is set properly, and using the debug mode, i can see that the reight object is used to pass the form data to my backend.

But when i look to the post request, the content-type is not changed, so my PHP script cannot handle the data properly.

find a the following capture describing what i believe is an issue :
image
image
image
image

Hi guys, i've been struggling with something that i believe is a bug on this excellent library: From the previous threads and the documentation, my understanding was that forms submitted through pjax are submitted with a content type set to "application/x-www-form-urlencoded". However, if the form has a enctype set to "multipart/form-data", the pjax call is supposed to use this value and set the header Content-Type to this value. I can't make it work on my server (Apache/PHP7) and despite the required enctype my data are sent as "application/x-www-form-urlencoded". the formData is set properly, and using the debug mode, i can see that the reight object is used to pass the form data to my backend. But when i look to the post request, the content-type is not changed, so my PHP script cannot handle the data properly. find a the following capture describing what i believe is an issue : ![image](https://user-images.githubusercontent.com/37553953/41785905-fd15b444-7611-11e8-8f93-f2ff73c02a22.png) ![image](https://user-images.githubusercontent.com/37553953/41785937-1726334a-7612-11e8-87c8-a89c534974ad.png) ![image](https://user-images.githubusercontent.com/37553953/41786041-6902b38c-7612-11e8-821d-3be86e056afa.png) ![image](https://user-images.githubusercontent.com/37553953/41786155-b9351142-7612-11e8-92bf-52621a4b378f.png)
robinnorth commented 2018-06-22 11:04:20 -05:00 (Migrated from github.com)

Hi @davidSocast, thanks for reporting this. Yes, looks like this is a bug as the Content-Type header is currently always set to "application/x-www-form-urlencoded" when submitting a form:

e49d8947f7/lib/send-request.js (L70-L73)

We'll look to fix this in the next release of the library.

Hi @davidSocast, thanks for reporting this. Yes, looks like this is a bug as the `Content-Type` header is currently always set to `"application/x-www-form-urlencoded"` when submitting a form: https://github.com/MoOx/pjax/blob/e49d8947f7ca00254d09920784bcf8a3e4e16f2d/lib/send-request.js#L70-L73 We'll look to fix this in the next release of the library.
BehindTheMath commented 2018-07-23 19:50:59 -05:00 (Migrated from github.com)

The fix for this should be simple: just add && !formData to the if statement. However, when I started writing tests for this, I ran into what I think is a bug in jsdom. So I'm going to wait until that's resolved to work on this.

The fix for this should be simple: just add `&& !formData` to the `if` statement. However, when I started writing tests for this, I ran into what I think is a [bug in jsdom](https://github.com/jsdom/jsdom/issues/2300). So I'm going to wait until that's resolved to work on this.
BehindTheMath commented 2018-08-13 19:56:53 -05:00 (Migrated from github.com)

The issue I opened in jsdom has not had a response in 3 weeks, so I'm submitting the fix for this, and the tests will have to wait.

The issue I opened in jsdom has not had a response in 3 weeks, so I'm submitting the fix for this, and the tests will have to wait.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: iLoveElysia/pjax#168