NaviServer Built-in Commands – 5.2.0a
ns_getform - Return an ns_set that contains all of the query data that was part of the HTTP request
This command returns a handle to an ns_set which contains all of the query data from the current HTTP request. The resulting data includes query parameters passed in the URL as well as multipart form data. If there is no form data, an empty ns_set is created.
This command returns a handle to an ns_set containing form data from the current HTTP request. It selects either the request body or the URL query parameters; it does not merge the two sources. If the selected source contains no data, an empty ns_set is returned.
Supported content types include application/x-www-form-urlencoded, multipart/form-data, and JSON media types. See ns_conn form for the content-type selection rules, including the compatibility exception that requests with a JSON content type and a zero-length body use the URL query parameters.
To access URL query parameters independently of the request content type and body, use:
set query [ns_parsequery [ns_conn query]]
This also works when both URL query parameters and a request body are supplied. The returned set contains only the URL query parameters.
In addition to the parsing performed by ns_conn form, ns_getform handles uploaded files. For each uploaded file field, two additional entries are created in the ns_set, named input_name.content-type and input_name.tmpfile. The latter contains the name of a temporary file holding the uploaded content. The temporary file is deleted automatically when the connection is closed.
For URL query parameters and URL-encoded or multipart form data, decoding errors can raise an exception with error code NS_INVALID_UTF8. The fallback charset specifies an alternative character set to try when the initial decoding produces invalid UTF-8. It can be configured through the global or per-server formfallbackcharset parameter. A warning is logged when invalid UTF-8 is encountered.
The option -fallbackcharset charset specifies the fallback charset explicitly, overriding the configuration setting.
ns_getform -fallbackcharset windows-1252
The positional charset argument sets the connection's URL charset, overriding the default established by urlcharset. This charset is used for URL query parameters and as the default for URL-encoded or multipart form data when no charset is specified. It differs from the fallback charset, which is used only after a decoding failure.
ns_getform iso8859-1
JSON body decoding uses the charset specified in the content-type header, defaulting to UTF-8. The positional charset argument and -fallbackcharset do not control JSON body decoding.