The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

can't get post parametres

ok.abdo's Avatar


14 Dec, 2015 04:21 PM

I'm trying to get post parameters inside the router callback function :

$app->post('/login', function ($request, $response, $args) {
but it gives me this error , Normally it's supposed to work :
Fatal error:  Call to undefined method Slim\Http\Request::post() in C:\xampp\htdocs\xxxs\index.php on line 21
  1. Support Staff 1 Posted by Rob Allen on 14 Dec, 2015 04:23 PM

    Rob Allen's Avatar

    in Slim3, you want $request->getParsedBody()['username'] or $request->getParam('username')

  2. 2 Posted by ok.abdo on 14 Dec, 2015 04:25 PM

    ok.abdo's Avatar

    @Allen Thank you I didn't notice that ...last time I worked with slim was like 2 years ago :D

  3. 3 Posted by Tony on 05 Jan, 2016 11:51 AM

    Tony's Avatar

    i gave your suggestion above a try...

    $app->post('/contact', function($request, $response, $args){
        $name = $request->getParam('name'); // by key
        $email = $request->getParam('email'); // by key
        $msg = $request->getParam('msg'); // by key
        //$data = $request->getParams(); // all data from query string or post body

        return $this->view->render($response, 'contact.twig');

    but slim3 comes up with following error...

    Method not allowed. Must be one of: POST

    Is this the correct post syntax for slim3?

  4. 4 Posted by slimguy on 05 Jan, 2016 02:05 PM

    slimguy's Avatar

    That error will show if you're sending a GET request to the server, and you don't have a GET route for '/contact'

    You can only post to that current route.

  5. 5 Posted by Filipe on 05 Jan, 2016 11:16 PM

    Filipe's Avatar

    Try to get POST parameter like this:

    $app->post('/admin', function ($request, $response, $args) {
    $message = $request->getParsedBody()['text'];

    return $response;


  6. 6 Posted by Tony on 06 Jan, 2016 06:25 AM

    Tony's Avatar


    I don't get an error when i use the get http method. So get on the form & get as my route. When i do this, the page renders(using twig too) & i get my query string in thr Uri .


    Only the post method. Slim not recognizing that its a POST request. I have post on the form & post in my route.

    i tried that but same result.

    $app->post('/contact', function($request, $response, $args){
    $fullname = $request->getParsedBody()['fname'];
    $email = $request->getParsedBody()['email'];
    $msg = $request->getParsedBody()['msg'];

        return $this->view->render($response, 'contact.twig');

    i don't know what's going on...

    any other suggestions?


  7. 7 Posted by Tony on 06 Jan, 2016 09:09 AM

    Tony's Avatar

    Finally a solution...

    two routes need to be created $app->get() & $app->post()

    the reason is that by executing the URL in the browser, this becomes a GET request.

    I var_dumped just to be sure the post form data values were passed using SUBMIT & they did. And when jumping to & from the /contact page , i echo out a string to verify when the get route is used.

    // CONTACT PAGE $app->post('/contact', function($request, $response, $args){ $fname = $request->getParam('fname'); $email = $request->getParam('email'); $msg = $request->getParam('msg');


    return $this->view->render($response, 'contact.twig');
    })->setName('contact'); // added route name

    // CONTACT PAGE $app->get('/contact', function($request, $response, $args){ echo "from side get route"; return $this->view->render($response, 'contact.twig'); })->setName('contact'); // added route name


  8. Josh Lockhart closed this discussion on 12 Feb, 2021 07:41 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac