Basic VSP Programming tutorial
Accessing Data in the Request How to access form data.

## Preliminaries

- Data supplied to a VSP is normally posted from a form.
- Pressing a form submit button causes the browser to pass the data to the server.
- The form data may be encoded in two forms: www-url-encoded or multipart/form-data.

## Processing of the form data in VSPs.

- When the request arrives, the web server parses the request and creates three input arguments for VSP processing:

  1. path - array with path elements of the requested URL path. Ie. if the request is "http://foo.bar/a/b/c" then "path" argument will be a vector ('a','b','c').
  2. params - array with name and value pairs of the passed form parameters
  3. lines - the vector of HTTP request header lines
- The form data is held in the "params" argument.

- The value of a named parameter can be extracted from the "params" array in two ways:

  1. Using the get_keyword function:

         declare x varchar;
         x := get_keyword('fieldname', params, 'default value');

  2. Using the {?'variable_name'} VSP shortcut.

         x := {?'fieldname'};

## Form example - A Simple Calculator.

The user can enter two numbers, and choose a desired operation. Pressing the "=" button causes the form to be sent to the server. The VSP execution will show the result of the calculation. This example uses the get_keyword function to retrieve the parameters.

## Form example - Insert table data

The second example demonstrates inserting the user entered form data into a table. This example uses the {?''} shortcuts for accessing the form data. The data in the table will be shown below the form, ordered by date. You must run the sample SQL first to create the table.

## Note

Note that both examples do not handle the SQL errors. The handling of SQL errors in VSPs will be described in section "VS-B-6".