getvar - get variable values

SYNOPSIS

<getvar [NOMSG] $var>


DESCRIPTION
The getvar function returns the values of the (single) variable named by getvar. It can be used in the rare situations where the name of a variable cannot be determined until run time, i.e. $var syntax cannot be used because the var name dynamically changes.

If NOMSG is given, it will not issue a putmsg if the given name is invalid and not found. This flag was added in Texis version 7.


DIAGNOSTICS
The getvar function returns the values of the (single) named variable.


EXAMPLE

<A NAME=main>
  <FORM METHOD=post ACTION="$url/test.html">
    First name: <INPUT NAME=First VALUE="$First">
    Last name:  <INPUT NAME=Last  VALUE="$Last">
    ... City, State, etc. ...
    <INPUT TYPE=submit>
  </FORM>
</A>

<A NAME=test>
  <varinfo LIST CGI>
  <$vars = $ret>
  <LOOP $vars>
    <getvar $vars>
    <rex "[^\alnum\space]+" $ret>
    <IF $ret neq "">
      Illegal character in $vars field.
    </IF>
  </LOOP>
</A>

In this example, a form with many text fields is submitted. Each field must be checked for illegal (non-alphanumeric) characters. Rather than laboriously call a function multiple times with hard-coded references to $First, $Last, $Street, etc., the list of form variables is dynamically obtained with varinfo, and each form variable is checked with getvar.


CAVEATS
The getvar function was added May 7 1997.

Where possible, it is more efficient to refer to variables directly by name than via getvar.

Non-CGI variables that are not explicitly used in the script somewhere with a $-sign, e.g. dynamically made-up variable names, cannot be used.


SEE ALSO
setvar, readvars, varinfo


Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.