Get CGI Variable

cgiGetVar, cgiGetVarI, cgiGetVarDec, cgiGetVarU, cgiGetVarL

The cgiGetVar procedures retrieve data from a variable sent to the program through the CGI process.

The cgiGetVar procedure is available in several formats. The basic procedure is cgiGetVar() that returns the raw value from the HTML form field to the CGI program. The other variations return the value after converting it to a specific format. The variations of the cgiGetVarxxxx procedure are as follows:

The HTML form data is automatically made available to the CGI program .

cgi-var-value  cgiGetVar(
  szVariable        256A    Const Varying 
  nOccur             10I 0  Const OPTIONS(*NOPASS)
)

See also: CleanNum, cgiGetVarCnt, cgiInit

Parameters

szVariable
[input VChar(256) const]  A string identifying the HTML Form field (cgi variable) to be returned. The variable identifier must be in the same letter case as the variable name used in the HTML source of the form.
nOccur [optional] DFT(1)
[input Int(4) const]  An optional occurrence index for the variable. Some HTML Form variables, such as the <SELECT> <OPTION> tags permit multiple selections to be made. This will cause multiple values for a specific variable to be returned. Use this parameter to identify which value you want to retrieve. If unspecified, the first or only value is returned. To determine the number of values available, use the cgiGetVarCnt() procedure.

Return Value

If the function succeeds, the return value is a text or numeric value (depending on which variation of this procedure is used) containing the data from the field in the HTML form.

If the function fails, no value is returned. Typically the function will fail if the value specified for the szVariable parameter is incorrect or is not included on the HTML form. One way to check the results is to verify that a value is returned, and if one is not returned verify the upper/lower case of the szVariable parameter with that of the form field name.

Remarks

Call cgiInit once for each invocation of your CGI program, then use the cgiGetVar procedures to return the values from the HTML form.

Example

.....DName+++++++++++EUDS.......Length+TDc.Functions+++++++++++++++++++++++++
     D CONTACT         S             20A
     D CMPNAME         S             30A  
     D PHONE           S             11P 0
 
.....C..n01..............OpCode(ex)Extended-factor2++++++++++++++++++++++++++++
     C                   callp     cgiInit()
     C                   eval      CONTACT = cgiGetVar('CONTACT')
     C                   eval      CMPNAME = cgiGetVar('COMPANY')
     C                   eval      PHONE   = cgiGetVarI('PHONE')

Note that under OS/400 Version 4, empty parentheses are not permitted following a procedure name; under OS/400 Version 5.1 and later, empty parentheses are permitted and strongly suggested.