Jump to content

997 998 999

Members
  • Posts

    2
  • Joined

  • Last visited

997 998 999's Achievements

Newbie

Newbie (2/6)

0

Reputation

  1. Hello, any way you can post your code showing how to get $_POST with JS fetch()? Thank you
  2. 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
×
×
  • Create New...