When I use
<form method="post" enctype="text/plain" action="proc.php">
form data can not be sent to proc.php file properly. Why? What is the problem? Why I can't use text/plain encoding with post but I can use it with get method?
When I use
<form method="post" enctype="text/plain" action="proc.php">
form data can not be sent to proc.php file properly. Why? What is the problem? Why I can't use text/plain encoding with post but I can use it with get method?
[Revised]
The answer is, because PHP doesn't handle it (and it is not a bug):
https://bugs.php.net/bug.php?id=33741
The first is the default, the second one you need only when you upload files.
@Alohci provided explanation why PHP doesn't populate
$_POST
array, but store the value inside a variable$HTTP_RAW_POST_DATA
.Example of what can go wrong with
text/plain
enctype:file1.php:
file2.php:
Result:
No way to distinguish what is the value of
input1
andinput2
variables. It can beabc\r\ninput2=def
, input2=ghi
, as well asabc
, input2=def\r\ninput2=ghi
No such problem when using the other two encodings mentioned before.
The difference between GET and POST:
enctype="text/plain"
- it just gets ignored by the browser; you can test it using Wireshark to sniff the request packets),text/plain
orapplication/x-www-form-urlencoded
, but the second one is the only non-ambiguous solution.HTML5 does define how to format form data submitted as
text/plain
here: http://dev.w3.org/html5/spec/association-of-controls-and-forms.html#plain-text-form-data.At the bottom of that section, it says:
So it not unreasonable that PHP does not attempt to interpret it and only makes it available in raw form. To me, that seems the correct approach.