CML Reference Guide

Chapter 4.1:  CML State Functions

[TOP] [UP] [NEXT]

The CML state functions are the glue that ties a group of CML pages and a Sweb server together.  To understand more about why they exist, see the design document "The Web Caucus".  For the CML author, it is only necessary to understand where they must be used.

$host()
Evaluates to the host name (and http port number) of the current host.  This is a useful way to build HTML links that require the current host name, and still keep your CML code portable.  Example:

"<A HREF="http://$host()/dir/page.html">some text</A>

$pid()
Evaluates to the pid (process id) and security code for the swebs server that is dedicated to your browser.  You must include this in links to CML pages.  Example:

"<A HREF="http://$host()/sweb/swebsock/$pid()/SP/test.cml?15+bye">
" name</A>

$arg(n)
Evaluates to the N'th argument to this CML page.  In the previous example, clicking on link "name" will bring up the CML page test.cml.  In test.cml, $arg(1) will then evaluate to "15", and $arg(2) will evaluate to "bye".

$inc(n)
Evaluates to the N'th argument to this "include" file.  See the include directive.

$form(name)
When a CML page is the "recipient" of an HTML form (as in <FORM ACTION="...">), the form data is available through the CML $form function.  The function evaluates to the data entered by the user in field name (as in NAME="name" in an <INPUT> or <TEXTAREA> HTML tag), or (in the case of TYPE="submit" fields) to the VALUE string for the button with NAME=name.  If there are multiple values for the field name (as in a <SELECT MULTIPLE> field), the values are concatenated together, separated by single spaces.

The $form() function transparently handles both standard ("application/x-www-form-urlencoded") and "multipart/form-data" forms.  $form() may be used only with METHOD=POST forms.

Multipart forms may be used with some browsers to upload an entire file, with an HTML tag of the form <INPUT TYPE="file" NAME="name">.  In this case, $form(name) evaluates to the name of a temporary file on the server host.  (The uploaded data has been placed in that file).  The temporary file will be automatically deleted when the swebs process exits (i.e., when the user's session is over).  The original name of the file is also available as $form(name.upload)

$debug(n)
N = 1 turns on debugging, which writes data to a logging file in /tmp. N = 0 turns off debugging.  The default is 0.

$caucus_id()
Evaluates to the name of the caucus userid, i.e. the userid that owns the Caucus files.