The following case demonstrates the advantages
HTML scripts, to control input forms
and to generate pop-up windows.
In the following examples, we have a single RPG CGI,
which adopts HTML scripts containing different degrees
You would read some naive code, still rather easy to be read
- In a
- In the
the HTML and the RPG sources on pop-up windows.
- In the
the two input forms (
- In the
- display the second page (the one containing the form
in a pop-up window, instead of using a full-screen window
- provide the final page as a replacement of the
first page (changing its location property)
though apparently looks similar to the fourth case,
provides a more elegant solution by
- replacing submit buttons with plain buttons
- providing the final page from the pop-up window
through submission of the form in the first page.
- When you develop a pop-up window
for use from many CGI programs
(as an example: a customer search pop-up),
you may want to use a variable name for the mother_window
input field receiving data from the pop-up.
This is what is done in our
3. Regular expressions
are patterns used to match character combinations in strings.
Regular expressions make up the base for whatever
form validation need.
For a complete description of regular expressions, see
Client Guide Chapter 4
From developer.netscape.com we have downloaded for you
which is available on iSeries 400 as
This sample code
- allows to learn a lot about making proficient use of
regular expressions for form validation
- contains numerous functions that you may immediately
use to validate your forms
- allows for an easy translation into national languages
Read an overview
Display the source code
Sample U.S. form
Sample international form
About credit card numbers ...
Test the code
- the sample U.S. form and
the sample international form
are just examples of validating input forms
- read the about credit card numbers
before running the examples
- if you make some changes to
run test the code
to make sure it is still working correctly.
After learning the FormChek.js functions,
we decided to write our own form validation example.
Our example deals with numeric input fields.
This example teaches:
- how to validate numeric inputs using masks built with
- how to shift (align) right numeric input data,
thus avoiding the CGI performing this task
- how to validate date inputs
Visit our example
Validating form numeric fields
More on validating forms
4. Handling cookies
Cookies are a mechanism for storing persistent data
on the client.
As HTTP is a stateless protocol, cookies provide a way to maintain
information between client requests.
In a sense, a cookie may be though of as a small data area
on the client.
A cookie has the following properties:
||Identifies the cookie (as if it were the name of a data area)
||The contents of the cookie (as if it were the value of a data area).
Note that Netscape Navigator does not support
blanks in the cookie value.
If that happens, the Set-Cookie string is trimmed right
at the first blank met.
Therefore it may be needed to substitute all the blanks
in a cookie value with some other character before creating
the cookie; in such a case, the opposite operation
should be performed after retrieving the cookie.
||The date until which the cookie should survive.
If the expiration is not specified, the cookie expires when
the user session ends.
||The domain under which the cookie can be retrieved.
If the domain is not specified, the web browser
should assume the host name of the server generating
||The path under which the cookie can be retrieved.
If the path is not specified, the web browser
should assume the path of the page generating
Cookies are stored and retrieved by the web browser.
- Netscape stores all cookies in file
Each cookie is a separate line.
- Microsoft Internet Explorer maintains an object for each cookie.
All these objects are collected in folder
Whenever a web page is loaded, the web browser makes available
all the unexpired cookies that:
For further details on the rules controlling access to cookies,
read Determining a Valid Cookie.
- match the domain of the page
(for instance, www.ibm.com or 220.127.116.11)
- are in the path of the page
(for instance, to page /js2p/cookie2.cgi
are made available all the cookies with path "/"
and all the cookies with path "/js2p".
There are two ways you may create and retrieve cookies:
- with CGI
You may create and retrieve cookies on the client through some
To create a cookie you must provide the following information:
- Cookie name
- Cookie value
- Expiration date and time (timestamp) (optional)
in a Web page. In this code you must just provide the
You do not have to provide
the domain name, the directory name, nor the expiration date.
please visit this
See our examples of handling Cookies
Basic example on handling a cookie
Advanced example on handling a cookie
4b. Handling cookies with CGI
Please refer to the section
in the CGIDEV2 CGI tutorial.