Input with POST method
This pages shows how to obtain and parse user input from the POST method.
Programming Issues
Most of the code is identical to the GET method example. The only differences are:
- We exit if the POST method is not used, rather than the GET method;
- We exit if
CONTENT_LENGTH
is zero, rather than if there is noQUERY_STRING
; - We exit if
CONTENT_LENGTH
is too long to avoid processing huge amounts of data. In this case, we have arbitrarily set the limit to 1,024 characters; and - We read the input from STDIN rather than from the
QUERY_STRING
.
Usage
You can only use the POST method from a form, such as the one below:
Note that we end up with multiple values in the "langsknown
" variable because we have used
the same name
attribute for each of the check boxes. In the CGI script, we have used "---
"
as the multiple separator, but in practice we would probably use \0
in case the user actually entered
"---
". Using \0
also allows us to treat langsknown
as a Perl list
if we want to do that.