简体   繁体   中英

How to get the form data using request->getBody() in slim framework using php?

I am trying the fetch the form data. I dont know where the mistake is.

<html>
<head>
<title>Student</title>
</head>
<body>
<form name="std" action="insert/std_insert" method="POST">
Student id:<input type="text" name="std_id" id="std_id"><br>
Student name:<input type="text" name="std_name" id="std_name"><br>
<input type="submit" name="submit" value="submit">
</body>
</html>

This is the code for fetching

<?php
error_reporting(0);
$app = new \Slim\Slim();
$body = $app->request->getBody();
echo json_encode($body);
?>

The request object is not full-filled until the app has been run. IE $app->run(); You are actually not using Slim correctly. docs.slimframework.com

Based on geggleto´s answer:

if( $request->isPost() ){
  $postdata_as_array = $request->getParsedBody();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM