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

Post parameters

Giulio's Avatar


03 Mar, 2016 08:48 PM


I have my api which validates required parameters:
function verifyRequiredParams($required_fields) {
    $error = false;
    $error_fields = "";

    $request_params = array();
    $request_params = $_REQUEST;

    // Handling PUT request params
    if ($_SERVER['REQUEST_METHOD'] == 'PUT') {
        $app = \Slim\Slim::getInstance();
        parse_str($app->request()->getBody(), $request_params);
    foreach ($required_fields as $field) {
        if (!isset($request_params[$field]) || strlen(trim($request_params[$field])) <= 0) {
            $error = true;
            $error_fields .= $field . ', ';
    if ($error) {
        // Required field(s) are missing or empty
        // echo error json and stop the app
        $response = array();
        $app = \Slim\Slim::getInstance();
        $response["error"] = true;
        $response["message"] = 'Required field(s) ' . substr($error_fields, 0, -2) . ' is missing or empty';
        echoRespnse(400, $response);

It works fine if I use standard web app or postman for example.
The request sends the parameters on [slim.request.form_hash] as this:
[slim.request.form_hash] => Array
              [IMEI] => aa

What I'm facing now is quite weird.

I'm developing an embedded application, using a GSM Module and I'm building the post request manually.
My sending information is:

POST /devices/deviceRegister HTTP/1.1
Accept: /
Connection: Keep-Alive
Content-Type: application/json
Content-Length: 14


Where IMEI is my body parameter.

My backend app receives the parameter on [slim.input] as this:
                    [slim.input] => Array
                            [IMEI] => aa

                    [slim.errors] => Resource id #5
                    [slim.input_original] => {"IMEI":"aa"}
                    [slim.request.form_hash] => Array

And my validation function returns parameter missing.

Why the parameter sits in different places ?
How can I solve it ?

Thank you

  1. 1 Posted by Giulio on 03 Mar, 2016 08:53 PM

    Giulio's Avatar

    More info:

    Call from postman printing $_REQUEST:
    array(1) {
      string(2) "aa"

    Call from my embedded application:
    array(0) {
               {"error":true,"message":"Required field(s) IMEI is missing or empty"}

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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