[ Previous ] [ Contents ] [ Index ] [ Next ]

ns_queryget

Overview

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

Syntax

ns_queryget key ?value?

Description

ns_queryget 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, "" 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 simply returned. 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:

Variable

Value

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.

Top of Page

[ Previous ] [ Contents ] [ Index ] [ Next ]
Copyright © 1996 America Online, Inc.