Ns queryget

From AOLserver Wiki
Revision as of 13:21, 5 November 2005 by 68.232.129.205 (talk)
Jump to navigation Jump to search

Man page: http://aolserver.com/docs/tcl/ns_queryget.html


NAME

ns_queryget - Get a value from the query data that was part of the HTTP request

SYNOPSIS

ns_queryget key ?value?

DESCRIPTION

This command looks in the query data for the specified key, and returns the value that was included in the HTTP request. If the key does not exist in the query data, an empty string is returned. The key is interpreted in a case-insensitive manner.
If the optional value argument is specified, and the key does not exist in the query data, the specified value is returned instead of an empty string. This capability allows for providing a default value if the key doesn't exist.
This function works for simple forms as well as for multipart formdata.
For files uploaded with the Netscape file upload widget, the file that was uploaded is an entry in the query data. See Example 3, below.

EXAMPLES

Example 1:
   set x [ns_queryget name]
   
If "name" is a key in the query data, the variable x will be set to the value associated with the "name" key. If "name" is not a key in the query data, "" will be returned.
Example 2:
   set x [ns_queryget name Hoover]
If "name" is a key in the query data, the variable x will be set to the value associated with the "name" key. If "name" is not a key in the query data, "Hoover" will be returned.
Example 3: Given this HTML form:
   <form enctype=multipart/form-data method=POST
      action=/formtest>
   Local file: <input name=clientfile type=file>
   To remote file: <INPUT TYPE=text NAME=path VALUE="" SIZE=80>
   <input name=submit type=submit value=Upload>
   </form>
   
and this POST handler:
   proc formtest { } {
       set remotefile [ns_queryget path]
       set localfile [ns_queryget clientfile]
       set where_the_data_is [ns_queryget clientfile.tmpfile]
   } ;# formtest
   
Suppose the user specified "spoon.txt" as the Local File and "/oop/ack/tick.txt" as the Remote File, and then submitted the form. The variable values in the formtest procedure will be: remotefile = "/oop/ack/tick.txt"
   localfile = "spoon.txt"
   _the_data = something like: "/var/tmp/baaa29444"
     
If you want to use the contents of the uploaded file, you can open it by executing:
   open [ns_queryget clientfile.tmpfile]
   
You can then read it and manipulate it as you want. Note, however, that this tmp file will be deleted once the connection closes.

NOTES

Note that despite it's name, ns_queryget works on POST form data as well as query string data.

SEE ALSO

ns_queryexists, ns_querygetall

Category Documentation - Category Core Tcl API