HTML Form data validation with Object REXX (Windows) 
Author Message
 HTML Form data validation with Object REXX (Windows)


here is another example of how to use Object REXX script code in a HTML
(IBM Object REXX for Windows V2R1 & Microsoft Internet Explorer).
This time, the example demonstrates three things:

1. How to validate the input data of a form with a script,
2. how to insert data into a form by script and
3. how to use "global" (by definition of Windows Scripting) variables.

It is often desirable that data the user has entered into a form is
before it is sent away. Here, it is checked whether a certain value is
and whether the choice from a drop-down list is valid.
Further, this example shows how to dynamically fill data into a form.
finally it shows how to make use of the feature of "global" variables
(variables the scripting engine considers global).

Here is the source code:

----file begins here

<TITLE>Object REXX and WSH #3</TITLE>
/* The next REXX line is "immediate code" in the WSH
   terminology. It gets executed right away.
   The variable LANGUAGE will from now on be a
   "global" variable whose contents can be accessed
   with the VALUE-BIF and the WSHPROPERTY selector */
language = (navigator~userLanguage)~substr(1,2)

/* This verifies that the data in the form is correct.
   If it is, .true is returned, .false otherwise. */
  proceed = .true
  form = document~forms~item(0)
  check = form~item("verify")~checked
  if check == .true then do
    amount = form~item("amount")~value
    if datatype(amount) \= "NUM" then do
      proceed = .false
      call alert "Please enter a numerical value for the amount!"
    selection = form~item("flavor")~value
    if selection = "" & proceed == .true then do
      proceed = .false
      call alert "Sorry, this item is out of stock!"

  return proceed


/* Obtain the language value from the script code
   that was executed above */
language = value('LANGUAGE',,'WSHPROPERTY')

when language = 'en' then greeting = "Welcome!"
when language = 'de' then greeting = "Willkommen!"
when language = 'es' then greeting = "Bienvenido!"
when language = 'fr' then greeting = "Bienvenue!"
  greeting = "Welcome!"

/* Print the greeting in the language of the user, if it is supported.
   Otherwise, print it in english. */
document~writeln("<H1>" greeting "</H1>")

This example shows how to verify the input data of a form before

<!-- Usually, the input data goes to a CGI script or similar that
     the data. Here, an eMail is sent that will be ignored... !-->
<FORM NAME="icecream"

      onSubmit="if verifyForm() == .false then return .false"
  <TH BGCOLOR="#cccccc" COLSPAN=2>Ice Cream Order</TH>
  <TD ALIGN=RIGHT><INPUT NAME="amount" SIZE=5 VALUE="0.5">kg</TD>
  <TD> <!-- The selection is left empty intentionally. It will be filled

            by script code after the FORM-Tag. !-->
       <SELECT NAME="flavor" SIZE=1></SELECT></TD>
      <INPUT TYPE=CHECKBOX NAME="verify" CHECKED>Verify form data</TD>

/* This script fills in the data in the form. Of course, since it
   is static, it could easily have been done by stating the items
   in the SELECT-Tag. Imagine the icecream information here was
   obtained in a dynamic way... */

form = document~forms~item(0)
selection = form~item("flavor")

do i over .array~of("Strawberry", "Vanilla", "Peppermint", "Chocolade",,

                    "Apple", "Banana (out of stock)", "Cherry (out of
  option = document~createElement("OPTION")
  option~text = i
  /* If this item is out of stock, set the value attribute
     of the option to an empty string. Otherwise, text and
     value of the option are the same. */
  if i~pos("out of stock") > 0 then
    option~value = ""
    option~value = i


----file ends here

In our documentation "Object REXX for Windows Reference" (chapter 21),
these things are described in detail. Here is a link to the download
page for the documentation:

http://www.*-*-*.com/ #public_pdf

The following link will take you to a reference on the objects that
can be used inside the Internet Explorer:


Kind regards,
Jan Engehausen, REXX Development, IBM Germany

Sun, 23 Nov 2003 19:27:33 GMT  
 HTML Form data validation with Object REXX (Windows)
Lieber Herr Engehausen,

finde Ihre Postings alle paar Wochen zu 2.1 super!

Vielleicht eine kleine Anregung: vielleicht k?nnten Sie alle bisherigen (und in Zukunft von Ihnen
kommenden) Postings zu diesem Thema im Netz zur Verfgung stellen? Z.B. ein kleiner Link
von der ORexx-Homepage mit einer kurzen Liste der bisherigen Beispiele mit Links zum
Source-Code sowie zur HTML-Datei, soda? 2.1-Benutzer es sofort ausprobieren k?nnen!
Sichtlich ;) kennen Sie sich mit der neuen Funktionalit ausgezeichnet aus, daher eine kleine
Bitte: seien Sie so freundlich und fgen einfach Einzeiler-Kommentare ein, wenn Sie Aufrufe an
den IE durchfhren, die den Zweck des Aufrufes pr?gnant erkl?ren. Dies wrde es Laien bzw.
Personen, die noch nie damit gearbeitet haben, *sehr* helfen, einen Bezug dazu aufzubauen.
(Nebenbei, auch Ihre WSH-Links zu Microsoft sind Gold wert, habe am Wochenende ein
wenig in ausgedrucktem Material geschm?kert!)

Mit freundlichem Gru?

Rony G. Flatscher

Fri, 28 Nov 2003 15:53:46 GMT  
 HTML Form data validation with Object REXX (Windows)
Hi there,

Sorry for this posting in German in comp.lang.rexx by mistake.
(Attempted to write to Jan Engehausen, expressing my thanks to his postings showing off some
of the new 2.1 features of Object Rexx and asking for a WWW-site in addition, so a sort of an
archive on these interesting and important issues develops over the course of time.)



> Lieber Herr Engehausen,

> finde Ihre Postings alle paar Wochen zu 2.1 super!

> ... cut ...

Fri, 28 Nov 2003 16:14:28 GMT  
 [ 3 post ] 

 Relevant Pages 

1. Date validation of input from HTML form

2. Object REXX in a HTML page (Windows)

3. How to call a Windows DDE (Dynamic Data Exchange) server from Object Rexx

4. Using a Web Based HTML Form to run Regina Rexx locally

5. Parsing HTML form output in REXX

6. getting data from html forms

7. getting form Object from html page using tcl

8. Support for REXX and Object REXX for Windows/AIX

9. Conversion OS/2 Rexx to Object Rexx for Windows '95

10. Announce: Update for Object REXX for Windows 95/Windows NT available

11. data validation and data format

12. data validation and data format


Powered by phpBB® Forum Software