Search the Community
Showing results for tags 'fetch'.
-
With JS fetch() it is a bit tricky to get for example $_POST populated (params need to be FormData / forms), but would it possible to get PW $input (get, post, urlSegments, queryString) working for fetch requests? Is there a fix / hook / workaround to solve it PW side?
- 2 replies
-
- querystring
- segments
- (and 4 more)
-
Hello, I'm trying to edit the field of a page with a value from a javascript fetch post request but I can't get the file_get_contents("php://input") or $_POST value in my PHP file. I created a `update` template and a `update` page (to allow access from fetch request and avoid 404/403/... errors) containing this code : $data = file_get_contents('php://input'); echo $data; # test edit the page field with random value #$home = $pages->get("/"); #$home->of(false); #$home->testfield = "test value"; #$home->save(); # test fetch response with random value #echo "test fetch response"; That I fetch request with my client javascript like this : fetch('/update', { method: 'POST', body: 'test' }) .then(function(response) { return response.text(); }) .then(function(data) { console.log(data); }) .catch(error => console.log('error')) } The field edit works fine and I get the test response from the `update` file but I can't get the posted value, I only get `<empty string>`. It is working fine outside of ProcessWire so I guess this is related to how PW handle $_POST ? I found this post where it seems to be working : Is there any way to get post value from javascript fetch request? What am I doing wrong? Thank you