|
PowerBuilder can create HTML form syntax for DataWindow objects that use the freeform or tabular DataWindow presentation styles. You can create an HTML form that displays a specified number of columns for a specified number of rows. Note the following:
- You create HTML form syntax by calling the GenerateHTMLForm function for the DataWindow control or DataStore
- The GenerateHTMLForm function creates HTML form syntax for the detail band only
- Embedded nested DataWindows display as HTML tables within the form
You typically create HTML forms dynamically when using Web.PB.
Presentation styles
Although the GenerateHTMLForm function generates syntax for all presentation styles, the only styles that create useable forms are freeform and tabular.
Edit style conversion
The GenerateHTMLForm function converts column edit styles into the appropriate HTML elements
|
Column edit style
|
HTML element
|
|
CheckBox
|
Input element specifying TYPE=CHECKBOX
|
|
DropDownDataWindow
|
Select element with a single Option element
|
|
DropDownListBox
|
Select element with one Option element for each item in the DropDownListBox
|
|
Edit
|
Input element specifying TYPE=TEXT
|
|
EditMask
|
|
|
RadioButtons
|
Input element specifying TYPE=RADIO
|
Generating syntax
To generate HTML form syntax, you call the GenerateHTMLForm function. Syntax for the GenerateHTMLForm function follows:
instancename.GenerateHTMLForm ( syntax, style, action { , startrow, endrow, startcolumn, endcolumn { , buffer } } )
The function places the Form element syntax into the syntax argument and the HTML stylesheet into the style argument, both of which are passed by reference.
Here is an example of the GenerateHTMLForm function:
Stringls_syntax, ls_style, ls_action Stringls_html Integerli_return
ls_action = & "/cgi-bin/pbcgi60.exe/myapp/uo_webtest/f_emplist" li_return = ds_1.GenerateHTMLForm & (ls_syntax, ls_style, ls_action) IF li_return = -1 THEN
MessageBox("HTML", "GenerateHTMLForm failed")
ELSE
// of_MakeHTMLPage is an object function, // described in the next section. ls_html = this.of_MakeHTMLPage & (ls_syntax, ls_style)
END IF
After calling the function, the ls_syntax variable contains a Form element, an example of which is shown below:
<FORM ACTION="/cgi-bin/pbcgi60.exe/myapp/uo_webtest/f_emplist" METHOD=POST> <P> <P><FONT CLASS=2>Employee ID:</FONT> <INPUT TYPE=TEXT NAME="emp_id_1" VALUE="501"> <P><FONT CLASS=2>Last Name:</FONT> <INPUT TYPE=TEXT NAME="emp_lname_1" MAXLENGTH=20 VALUE="Scott"> <P><FONT CLASS=2>First Name:</FONT> <INPUT TYPE=TEXT NAME="emp_fname_1" MAXLENGTH=20 VALUE="David"> <P><FONT CLASS=2>Status:</FONT> <INPUT TYPE="RADIO" NAME="status_1" CHECKED CLASS=5 ><FONT CLASS=5 >Active <P> <INPUT TYPE="RADIO" NAME="status_1" CLASS=5 ><FONT CLASS=5 >Terminated <P> <INPUT TYPE="RADIO" NAME="status_1" CLASS=5 ><FONT CLASS=5 >On Leave <P> <P><BR><INPUT TYPE=SUBMIT NAME=SAMPLE VALUE="OK"> </FORM>
The ls_stylesheet variable from the previous example contains a Style element, an example of which is shown below:
<STYLE TYPE="text/css"> <!-- .2{COLOR:#000000;BACKGROUND:#000000;FONT-STYLE:normal;FONT-WEIGHT:normal;FONT:9pt "Arial", sans-serif;TEXT-DECORATION:none} .3{COLOR:#000000;BACKGROUND:#000000;FONT-STYLE:normal;FONT-WEIGHT:normal;FONT:8pt "MS Sans Serif", sans-serif;TEXT-DECORATION:none} .5{COLOR:#000000;BACKGROUND:#000000;FONT-STYLE:normal;FONT-WEIGHT:normal;FONT:8pt "MS Sans Serif", sans-serif;TEXT-DECORATION:none} --> </STYLE>
PowerBuilder creates unique element names
The GenerateHTMLForm function creates unique field names for all elements in the form, even when displaying multiple rows in one form.
Creating an HTML page
To use the syntax and stylesheet returned by the GenerateHTMLForm function, you must write code to merge them into an HTML page. A complete HTML page requires <HTML> and <BODY> elements to contain the stylesheet and syntax.
One way to do this is to create a global or object function that returns a complete HTML page, taking as arguments, the Form and Style elements generated by the GenerateHTMLForm function. Such a function might contain the following code:
// Function Name: of_MakeHTMLPage // Arguments:Stringas_syntax //Stringas_style // Returns:String //*********************************** Stringls_html
IF as_syntax = "" THEN Return "" END IF IF as_style = "" THEN Return "" END IF ls_html = "<HTML>" ls_html += as_style ls_html += "<BODY>" ls_html += "<H1>Employee Information</H1>" ls_html += as_syntax ls_html += "</BODY></HTML>" Return ls_html
|