Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http response code 302 displays error msg #15

Closed
mizmiz opened this issue Jul 23, 2020 · 11 comments
Closed

Http response code 302 displays error msg #15

mizmiz opened this issue Jul 23, 2020 · 11 comments
Assignees
Labels

Comments

@mizmiz
Copy link

mizmiz commented Jul 23, 2020

Description

Form submitted via ajax displays error message "Couldn’t save submission due to errors. 302: Found"

In src/web/assets/frontend/src/js/formie-form.js is says

if (xhr.status >= 200 && xhr.status < 300) {
...
}

shouldn't it be
< 400
instead as 30x codes do not necessarily indicate errors?

Form settings

  • Multi-page form: No
  • Submission Method: Ajax
  • Client-side Validation: Yes
  • Custom Form Templates: Yes

Additional info

  • Plugin version: 1.0.4
  • Craft version: 3.4.24
@engram-design
Copy link
Member

Well, for an Ajax-based response, a 30x response isn't ideal. Can you shoot through the headers for the response back from the controller? The controller should detect an ajax request and respond with a payload, rather than a redirect (302) response.

@mizmiz
Copy link
Author

mizmiz commented Jul 23, 2020

The response header includes a X-Redirect. I think it is caused somewhere in the getParsedValue method. But I don`t really understand why or how.

Response Headers

Cache-Control: no-store, no-cache, must-revalidate
Connection: Keep-Alive
Content-Type: application/json; charset=UTF-8
Date: Thu, 23 Jul 2020 10:51:24 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive: timeout=5, max=100
Pragma: no-cache
Server: Apache/2.4.25 (Debian)
Set-Cookie: 1031b8c41dfff97a311a7ac99863bdc5_identity=1535533d61494f3a874e032f481cda966f0e9172b2338fe3613fca0dcccf69faa%3A2%3A%7Bi%3A0%3Bs%3A41%3A%221031b8c41dfff97a311a7ac99863bdc5_identity%22%3Bi%3A1%3Bs%3A249%3A%22%5B%221%22%2C%22%5B%5C%22NkDONq2fbW12xkG-5Yf9hADIQhope_2_wndXnxvuJKaNyeXxZS_bj9b_3f78GfHHlTw628eg0GrphwyuADMxByFKUIp9ujBF5nUq%5C%22%2Cnull%2C%5C%22Mozilla%2F5.0+%28Macintosh%3B+Intel+Mac+OS+X+10_15_6%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F84.0.4147.89+Safari%2F537.36%5C%22%5D%22%2C3600%5D%22%3B%7D; expires=Thu, 23-Jul-2020 11:51:24 GMT; Max-Age=3600; path=/; secure; HttpOnly
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Debug-Duration: 399
X-Debug-Link: https://dev.[…].io/index.php?p=actions/debug/default/view&tag=5f196bac61e6f
X-Debug-Tag: 5f196bac61e6f
X-Powered-By: Craft CMS
X-Redirect: https://dev.[…].io/de/
X-UA-Compatible: IE=edge

The Response payload seems perfectly fine though:
{"success":true,"submissionId":95081,"currentPageId":"1518","nextPageId":null,"nextPageIndex":0,"totalPages":1}

@engram-design
Copy link
Member

You mentioned you're using Custom Form Templates, are you using the default theme JS or rolling your own?

I'll try and re-create this and see how I go, if we want to change that. I was more concerned about a 30x response for an Ajax request isn't correct in any case. I'll get back to you after testing.

@mizmiz
Copy link
Author

mizmiz commented Jul 23, 2020

I am using the default JS.

@engram-design engram-design self-assigned this Jul 24, 2020
@engram-design
Copy link
Member

Just circling back to this, can you send through your request headers, not just the response headers? It seems like something might be going on with X-Redirect: https://dev.[…].io/de/ and your multi-site? Wondering if there's any details on your setup you could share?

@mizmiz
Copy link
Author

mizmiz commented Jul 26, 2020

Request Headers

Accept: application/json
Accept-Encoding: gzip, deflate, br
Accept-Language: de-DE,de;q=0.9,fr;q=0.8,en;q=0.7,zh;q=0.6,en-US;q=0.5
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 694
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary9gl6lP30W0SOxMUG
Cookie: 1031b8c41dfff97a311a7ac99863bdc5_username=3c5e93a8e2d4835d1e27fe52e089cdebbd671e4b45f12cf82d9ad01c31f483c8a%3A2%3A%7Bi%3A0%3Bs%3A41%3A%221031b8c41dfff97a311a7ac99863bdc5_username%22%3Bi%3A1%3Bs%3A5%3A%22admin%22%3B%7D; md-cookie-settings={%22strictlyNecessary%22:true%2C%22functional%22:true%2C%22analytics%22:true}; __stripe_mid=93c303e0-f166-4b94-b0b6-198d8f6f49a7; md-country-code=9feb61a5bf1c9ffcee91aac1f8a1f1ed4fdd6051584bb9cc836bb653fc62b9cba%3A2%3A%7Bi%3A0%3Bs%3A15%3A%22md-country-code%22%3Bi%3A1%3Bs%3A2%3A%22DE%22%3B%7D; CraftSessionId=eigaik3agrmrbblig8gsakecdh; CRAFT_CSRF_TOKEN=600fd6a16e94636917fbcede02cc28dc94b6c2d2e4ced84c1a2c17e414e093f5a%3A2%3A%7Bi%3A0%3Bs%3A16%3A%22CRAFT_CSRF_TOKEN%22%3Bi%3A1%3Bs%3A40%3A%22y03zRXWE-Zy--a6dU3E8dmNbGYJloJJ43zfF9c8y%22%3B%7D; md-logo-type=1; _pk_ses.24.e18d=1; _pk_id.24.e18d=854770d35a0a3f77.1595234227.22.1595774005.1595773948.
Host: dev.[…].io
Origin: https://dev.[…].io
Pragma: no-cache
Referer: https://dev.[…].io/de/kontakt
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36
X-Requested-With: XMLHttpRequest

@engram-design
Copy link
Member

Thanks for this. Is your site a multi-site? Is there some redirection going on for https://dev.[…].io/ to go to https://dev.[…].io/de?

@mizmiz
Copy link
Author

mizmiz commented Jul 27, 2020

Hi Josh, I got to the bottom of this. The redirect is caused by another custom made plugin of ours.

@engram-design
Copy link
Member

Ah, glad you got to the bottom of it. I'll still consider allowing 30x responses not marked as errors for ajax-based requests.

@mizmiz
Copy link
Author

mizmiz commented Jul 27, 2020

Well maybe there should not be redirects in POST requests.

@engram-design
Copy link
Member

For an Ajax request there shouldn't be any legitimate reason you get a redirect response from Craft, hence why I was trying to see if it was a deeper issue. If there's a redirect setup for a successful form entry, its done through JS.

For traditional POST-ing to the server, again, the only redirect response you should receive is if you have redirection setup for a successful submission

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants