Method = "post" enctype = "text / plain" are not compatible?
When i use
<form method="post" enctype="text/plain" action="proc.php"> form data cannot be sent to the proc.php file properly. What for? What is the problem? Why can't I use text / plain encoding with a message, but can I use it with the get method?
[After revision]
The answer is that PHP cannot handle this (and this is not an error):
https://bugs.php.net/bug.php?id=33741
Valid values for enctype in <form> tag are: application/x-www-form-urlencoded multipart/form-data The first is the default, the second is only when downloading files.
@Alohci provided an explanation of why PHP does not populate the $_POST array, but stores the value inside the $HTTP_RAW_POST_DATA variable.
An example of what might go wrong with text/plain enctype:
file1.php:
<form method="post" enctype="text/plain" action="file2.php"> <textarea name="input1">abc input2=def</textarea> <input name="input2" value="ghi" /> <input type="submit"> </form> file2.php:
<?php print($HTTP_RAW_POST_DATA); ?> Result:
input1=abc input2=def input2=ghi It is impossible to distinguish what the variables input1 and input2 . It could be
- input1 =
abc\r\ninput2=def, input2 =ghi, and also - input1 =
abc, input2 =def\r\ninput2=ghi
There is no such problem when using the other two encodings mentioned earlier.
The difference between GET and POST:
- in GET, variables are part of the URL and present in the URL as a query string, so they must be encoded in the URL (and even if you write
enctype="text/plain"- this is simply ignored by the browser, you can test it using Wireshark to sniff request packets) - when sending a POST, the variables are not part of the URL, but are sent as the last header in the HTTP request (POSTDATA), and you can choose whether you want to send them as
text/plainorapplication/x-www-form-urlencoded, but the second is the only unambiguous solution.
HTML5 defines how to format form data presented as text/plain here: https://w3c.imtqy.com/html/sec-forms.html#plain-text-form-data .
At the bottom of this section is written:
Useful data using the text / plain format is intended for human readability. They cannot be reliably interpreted by the computer, since the format is ambiguous (for example, there is no way to distinguish the literal newline in the value from the newline at the end of the value).
Therefore, it is possible that PHP does not try to interpret it, but only makes it available in raw form. It seems to me the right approach.