var
| Rivet Tcl Commands and Variables |

## Name

var, var_qs, var_post — get the value of a form variable.

## Synopsis

::rivet::var (get | list | exists | number | all)
::rivet::var_qs (get | list | exists | number | all)
::rivet::var_post (get | list | exists | number | all)

## Description

The var command retrieves information about GET or POST variables sent to the script via client request. It treats both GET and POST variables the same, regardless of their origin. Note that there are two additional forms of ::rivet::var: rivet::var_qs and ::rivet::var_post. These two restrict the retrieval of information to parameters arriving via the querystring (?foo=bar&bee=bop) or POSTing, respectively.

::rivet::var get ?`varname`? ?`?default?`?
  Returns the value of variable `varname` as a string (even if there are multiple values). If the variable doesn't exist as a GET or POST variable, the `?default?` value is returned, otherwise "" - an empty string - is returned.
::rivet::var list ?`varname`?
  Returns the value of variable `varname` as a list, one list element per reference. Radiobuttons or multiple selection listboxes are suited widgets which may return list data.
  If the result list is passed as a default value to the form package, one could also set index "__varname" to get it interpreted as a list.

      set response(countries) [::rivet::var list countries]
      set response(__countries) ""
      form form_request -defaults response
      form_request select countries -multiple 1 -values {USA Canada Mexico}
      form_request end

::rivet::var exists ?`varname`?
  Returns 1 if `varname` exists, 0 if it doesn't.
::rivet::var number
  Returns the number of variables.
::rivet::var all ?`?default_values?`?
  Return a list of variable names and values. This is a flat list of key value pairs and as such can be intepreted as the representation of a single level dictionary. An optional argument is interpreted as a dictionary of default values

See Example 3, “Variable Access”.

url_script |  | with_binary_output