Calling a Form - from a Java-Free Browse Box

By Vince Russo

Posted March 1 1999

Printer-friendly version

Background

Internet Connect uses Java Applets that operate in a browser; therefore a Java Enabled browser is necessary. This can cause problems because not all browsers support Java the same way and the ones that do, don't always work in the same way. By using Tony Goldstein's template modifications we enable Internet Connect to function without Java. This ensures that the application will operate in all browsers, Java supporting or not.

An Internet enabled Clarion application is a windows program running on a server. The program sends and receives HTML and parameters through the Clarion Application Broker to a web browser. The browser window is an HTML representation of the program running on the server.

HTML Form Fields and Objects

HTML - ("Hyper-Text Markup Language")

For those of you that are not familiar with HTML here are some basics.

HTML is a language made up of a set of symbols called "Tags". HTML "Tags" are placed in an ASCII text document to define the appearance of a Web page. They also control things like font style, font size, colors, tables, etc. Internet Connect creates all the HTML code for us, unless we specify otherwise (by checking the do not generate default html for control).

HTML FORMS

In Clarion when input is required we use a form procedure.

In HTML, when input is required we use the <Form> Tag followed by "Input Type Tags". All input is done within the <Form> Tags.

If we look at a Clarion created HTML page (what is output to the browser from the broker) we will see that our entry fields, checkboxes, radio buttons, submit buttons, etc. are all within the <Form> Tags.

On an HTML form every object has a name referencing it, even the FORM itself has an identity. This is so we can reference it in our processing. This is similar to using a variable; label or field equate label in Clarion.

Below is an example of an HTML Form with a few form elements

<FORM NAME="FORM1" METHOD="POST" ACTION=http://cgi-bin/process.exe>

<INPUT TYPE="TEXT" NAME="FULLNAME" MAXLENGTH=10 SIZE=10>

<INPUT TYPE="CHECKBOX" NAME="CHECK1" VALUE="YES" CHECKED>Yes

<INPUT TYPE="SUBMIT" NAME="SEND" VALUE="SEND CONTENTS">

</FORM>

In the example above, we are telling the browser that we want to define a Form for data input called "FORM1." When the form is completed, we define an "Action," in this case a program somewhere to process the data and we "POST"- send the data using CGI (Common Gateway Interface) - the data from the form.

The form also has a "Text" Entry Field called "Fullname." It is limited to 10 characters and the display length is also 10 characters. Finally, there is a "Checkbox" named "Check1" and it has the default value of "Checked."

These names, similar to Clarion Use variables, allow the processing application to identify what is being submitted to the server. These values are submitted when a button of the type "SUBMIT" on the form is pressed. Values can be passed by a link or by the submit button (the data is sent URL encoded).

What we want to do is replicate the technique the Internet Connect templates use to create the Name and Value of an object on an HTML form back to our application.

Passing a value back to our application is as "easy" as creating a link that points back into our application with parameters that follow. Well, Internet Connect does this, if we know how to create the required HTML attributes.

When Clarion displays records in a list box, the records are read from a file and stored in a queue. Each queue entry has a pointer which is useable as a position or index number. The user highlights a row in the list box, the queue position is retrieved and the correct file record is retrieved from disk and then displayed on the form. So all we need to do is accomplish these two "simple" steps using our HTML representation.

In fact, the only thing (in addition the name and Action) we really need to do is get the queue reference. Clarion handles record retrieval automatically.

The Internet Connect Classes

In The "Best of Both Worlds: Browse Boxes on the Web" (Clarion Online, 2, 7, February 1999), we discussed how to build a browse box using a standard Clarion browse and an HTML table. I would like to take the next step: Calling a standard Clarion Form from an HTML table (or appearing to do so). We are going to be using two methods from the IC Classes to achieve this.

Communicating in HTML and Clarion.

How are we going to do this?

Simple; using the methods GetControlReference() and IC:Feq2Id().

GetControlReference(?Control)

  • Returns an internal Control Reference Number pertaining to the application currently executing.
  • Prototyped in ICSTD.INC
  • Found in the ICSTD.CLW file in the \libsrc directory of Clarion

IC:Feq2Id(?Control)

  • Returns the Id Number used in an HTML Form referenced to the use equate of the Clarion (?Control.)
  • Prototyped in ICHTML.INC
  • Found in the ICHTML.CLW file in the \libsrc directory of Clarion

If we analyze the code that Internet Connect creates, we see that every object inbetween the <FORM> tags has a name. Internet Connect assigns an Id Number or Name for controls using the format of X30000 incremented consecutively. This Id Number is referenced to a ?Control equate in Clarion. This is the HTML Name and what we are going to replicate in our code. We are going to assign a value to the Id Number and pass it back to our program for processing. The technique that we are going to use is a link back into our application.

As Steve Parker points out in his article elsewhere in this issue, the standard Insert button continues to work as expected as long as we continue to use the built in queue manager. So, we will look at the Change and Delete buttons here.

We will be calling a link back into our Clarion application and passing the value or values of the objects on our form.

Button controls are either pushed or not-pushed, so the equate of a pushed button is 1.

Using the HTML Table we created in the previous article "The Best of Both Worlds: Browse Boxes on the Web," add another table data (<TD>) to the table.

Inside this cell we want to create a link referencing our application. The link will be the equivalent of pushing the change button, telling the application that we want to change/view a record. The link assigns a value of 1 (1=pushed) to the Change button's Id Number.

Okay now we have told the application that the change button has been pressed but we also need to tell our application what file record we wish to change/view. This is where we use the record queue counter i# (the variable used in our code to track the queue entry position). i# is the value we assign to the Id Number referenced to the browse box (it also has to be included in the link)

To reiterate, all we are sending back to our application is that the Change button as been pressed and the position in the queue of the file record we wish to Change/View.

Entries# = RECORDS(Queue:Browse:1)    ! Determine number of entries
LOOP i# = 1 to Entries#                 ! Loop through QUEUE
 GET(Queue:Browse:1,i#)                ! Get record from QUEUE
  IF ERRORCODE() THEN STOP(ERROR()).
  HTMLString = Clip (HTMLString) & '<<tr><<td>'& |
                                 <<A
                                 Href="'&Target.GetControlReference(?Change)&'=
                                 1&X'& IC:Feq2Id(?Browse:1)&'='&i#-
                                 1&'">Change/View</A>' &|
                                 '<<tr><<td>' & pre:LastName & '<</td><<td>' &|
                                 pre:FirstName & '<</td><<td>' & pre:PhoneNumber &|
                                 '<</td><</tr>'
End                              ! Queue entries loop

In the example above, one modification is necessary. The queue entry must be referenced directly instead of the file buffer (e.g., Queue:Browse:1.pre:FirstName)

This is the key to calling our form:

<A
Href="'&Target.GetControlReference(?Change)&'=1&X'&IC:Feq2Id(?Browse:1)&'='
&I#-1&'">Change/View</A>

<A Href="'&Target.GetControlReference(?Change)is a hypertext link referenced to the internal reference number of the processing Clarion application. Assign a value of 1 to the Id Number referenced to the change button. We are simply telling the processing application that the change button has been pressed. 'X'&IC:Feq2Id(?Browse:1)&'='i#-1 is assigning a value to the Id Number of the Clarion browse box control (i# is our queue position in our example above and the -1 is to subtract 1 from the queue position). When I experimented with this technique the returned record was always one ahead so I added -1 not sure why but it works.

The '>Change/View</A>' is the display portion of the link.

Target.GetControlReference()returns both the internal reference number of the processing application and the Id Number of the control within the perenthesis. The internal reference number of the processing application only needs to appear once on the link. IC:Feq2Id()returns just the control reference number onlywithout the 'X' prefix, this has to be added manually.

In other words, Target.GetControlReference() returns both the HTML name of the control that was "pressed" but also the Action (a reference to the app itself).

The HTML code produced from the above statements might look like:

<A Href="/DEMO.EXE.468451660?X30022=1&X30023=2">Change/View</A>

A demo program can be located atwww.autohotline.com/cws/cwlaunch.dll/demo/demo.exe.0

That's all there is to it!

(Author's note: I would like to thank Steve Parker for his contributions in helping to prepare this article.)

Article comments

Post a comment

You must be logged on to post comments.

Clarion Roadmap

Try the roadmap (beta)

Search ClarionMag

 

Advanced search

From the archives

Superfiles and NAME

9/14/2009 12:00:00 AM

Having covered Superfiles in the previous episode, Steve Parker tackles the intricacies of how to set arbitrary names for the tables inside Superfiles.