getvar - get variable values


<getvar [NOMSG] $var>

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.

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


<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>

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

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.

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.

setvar, readvars, varinfo

Copyright © Thunderstone Software     Last updated: Oct 24 2023
Copyright © 2024 Thunderstone Software LLC. All rights reserved.