Tcl Library Source Code

Documentation
Login
EuroTcl/OpenACS 11 - 12 JULY 2024, VIENNA


[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]

NAME

ncgi - Procedures to manipulate CGI values.

Table Of Contents

SYNOPSIS

package require Tcl 8.5 9
package require ncgi ?1.4.5?

::ncgi::cookie cookie
::ncgi::decode str
::ncgi::empty name
::ncgi::exists name
::ncgi::encode string
::ncgi::header ?type? args
::ncgi::import cginame ?tclname?
::ncgi::importAll args
::ncgi::importFile cmd cginame ?filename?
::ncgi::input ?fakeinput? ?fakecookie?
::ncgi::multipart type query
::ncgi::nvlist
::ncgi::names
::ncgi::parse
::ncgi::parseMimeValue value
::ncgi::query
::ncgi::redirect url
::ncgi::reset query type
::ncgi::setCookie args
::ncgi::setDefaultValue key defvalue
::ncgi::setDefaultValueList key defvaluelist
::ncgi::setValue key value
::ncgi::setValueList key valuelist
::ncgi::type
::ncgi::urlStub ?url?
::ncgi::value key ?default?
::ncgi::valueList key ?default?

DESCRIPTION

The ncgi package provides commands that manipulate CGI values. These are values that come from Web forms and are processed either by CGI scripts or web pages with embedded Tcl code. Use the ncgi package to query these values, set and get cookies, and encode and decode www-url-encoded values.

In the simplest case, a CGI script first calls ::ncgi::parse and then calls ::ncgi::value to get different form values. If a CGI value is repeated, you should use ::ncgi::valueList to get back the complete list of values.

An alternative to ::ncgi::parse is ::ncgi::input, which has semantics similar to Don Libes' cgi_input procedure. ::ncgi::input restricts repeated CGI values to have names that end with "List". In this case, ::ncgi::value will return the complete list of values, and ::ncgi::input will raise errors if it find repeated form elements without the right name.

The ::ncgi::reset procedure can be used in test suites and Web servers to initialize the source of the CGI values. Otherwise the values are read in from the CGI environment.

The complete set of procedures is described below.

EXAMPLES

Uploading a file

HTML:
<html>
<form action="/cgi-bin/upload.cgi" method="POST" enctype="multipart/form-data">
Path: <input type="file" name="filedata"><br>
Name: <input type="text" name="filedesc"><br>
<input type="submit">
</form>
</html>

TCL: upload.cgi
#!/usr/local/bin/tclsh

::ncgi::parse
set filedata [::ncgi::value filedata]
set filedesc [::ncgi::value filedesc]

puts "<html> File uploaded at <a href=\"/images/$filedesc\">$filedesc</a> </html>"

set filename /www/images/$filedesc

set fh [open $filename w]
puts -nonewline $fh $filedata
close $fh

Bugs, Ideas, Feedback

This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category ncgi of the Tcllib Trackers. Please also report any ideas for enhancements you may have for either package and/or documentation.

When proposing code changes, please provide unified diffs, i.e the output of diff -u.

Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.

SEE ALSO

html

KEYWORDS

CGI, cookie, form, html

CATEGORY

CGI programming