0

i request method patch in php but, There was a problem Undefined index variable from use $_POST and $_GET

javascript

 document.getElementById("editevent").addEventListener("submit", (e) => {
    e.preventDefault();
    let form = document.querySelector("#editevent");
    const data = new FormData();
    for (const p of new FormData(form)) {
      data.append(p[0], p[1]);
    }
  
    fetch(`../mufevent/class/event.php/${id}`, {
     
      method: "PATCH",
      body: data,
    
    })
      .then((response) => response.text())
      .then((response) => {
        console.log(response);
        alert(response);
      
      });

to: file.php

if ($_SERVER['REQUEST_METHOD'] == "PATCH") {
   
    echo $_POST['date'];
}
  • Did you try the `$_REQUEST` variable? – Taplar Sep 01 '20 at 17:39
  • PHP doesn't populate those variables for PATCH requests. You need to get the raw request body and parse it yourself. You can see in the link above how to get that data. – M. Eriksson Sep 01 '20 at 17:51

0 Answers0