Php - Form - HTTP Request/Response

About

Form and HTTP Fetch in php

Form

Php does not support multiple form control with the same name.

Even if it receive several values for the same name via a valid multipart-form-data, it will pass only the last value to the $_POST global variable.

To resolve this issue at the php sauce, you need to:

  • add bracket to the name value (ie my-input-name[])
  • or use unique name value

Although HTML allows multiple values regardless of name, PHP doesn't, and this behaviour is well established. Closing won't fix.

Http

Post

The $_POST 1) global variable is build by php when the body of the request has:

For other format, you need to build the $_POST global variable yourself from the body available via the input stream.

Example with content-type set to Json

if ($_SERVER["CONTENT_TYPE"] === "application/json") {
    $_POST = json_decode(file_get_contents('php://input'), true);
}

Documentation / Reference


Powered by ComboStrap