Basic VSP Programming
VS-B-3 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:
- 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').
- params - array with name and value pairs of the passed form parameters
- 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:
- Using the get_keyword function:
declare x varchar; x := get_keyword('fieldname', params, 'default value'); - Using the {?'variable_name'} VSP shortcut.
x := {?'fieldname'};
- Using the get_keyword function:
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".
| View the source | Action |
|---|---|
| 1. vs_b_3_sample_2.sql | Set the initial state |
| 2. vs_b_3_sample_1.vsp | Run |
| 3. vs_b_3_sample_2.vsp | Run |
OpenLink Home
Technical Support