HTML blocks define the layout of the Web page, reference variables, and call functions. HTML blocks are used as entry and exit points from the macro. An HTML block is always specified in the Net.Data macro request and every macro must have at least one HTML block.
The first HTML block in the example macro is named INPUT. The HTML(INPUT) contains the HTML for a simple form with one input field.
%{ ********************** HTML Block: Input ************************%} %HTML (INPUT) { <--- Identifies the name of this HTML block. <html> <head> <title>$(page_title)</title> <--- Note the variable substitution. </head><body> <h1>Input Form</h1> Today is @today() <--- This line contains a call to a function. <FORM METHOD="post" ACTION="OUTPUT"> <--- When this form is submitted, the "OUTPUT" HTML block is called. Type some data to pass to a REXX program: <INPUT NAME="input_data" <--- "input_data" is defined when the form TYPE="text" SIZE="30"> is submitted and can be referenced elsewhere in this macro. It is initialized to whatever the user types into the input field. <p> <INPUT TYPE="submit" VALUE="Enter"> <hr> <p> [ <a href="/">Home page</a>] </body><html> %} <--- Closes the HTML block.
The entire block is surrounded by the HTML block identifier, %HTML (INPUT) {...%}. INPUT identifies the name of this block. The name can contain any alphanumeric character, underscores, or periods. The HTML <title> tag contains an example of variable substitution. The value of the variable page_title is substituted into the title of the form.
This block also has a function call. The expression @today() is a call to the function today. This function is defined in the FUNCTION block that is described above. Net.Data inserts the result of the today function, the current date, into the HTML text in the same location that the @today() expression is located.
The ACTION parameter of the FORM statement provides an example of navigation between HTML blocks or between macros. Referencing the name of another block in an ACTION parameter accesses that block when the form is submitted. Any input data from an HTML form is passed to the block as implicit variables. This is true of the single input field defined on this form. When the form is submitted, data entered in this form is passed to the HTML(OUTPUT) block in the variable input_data.
You can access HTML blocks in other macros with a relative reference if the macros are on the same Web server. For example, the ACTION parameter ACTION="../othermacro.d2w/main" accesses the HTML block called main in the macro othermacro.d2w. Again, any data entered into the form is passed to this macro in the variable input_data.
When you invoke Net.Data, you pass the variable as part of the URL. For example:
<a href="/cgi-bin/db2www/othermacro.d2w/main?input_data=value">Next macro</a>
You can access or manipulate form data in the macro by referencing the variable name specified in the form.
The next HTML block in the example is the HTML(OUTPUT) block. It contains the HTML tagging and Net.Data macro statements that define the output processed from the HTML(INPUT) request.
%{ ********************** HTML Block: Output ************************%} %HTML (OUTPUT) { <html> <head> <title>$(page_title)</title> <--- More substitution. </head><body> <h1>Output Page</h1> <p>@rexx1(input_data) <--- This line contains a call to function rexx1 passing the argument "input_data". <p> <hr> <p> [ <a href="/">Home page</a> | <a href="input">Previous page</a>] %}
Like the HTML(INPUT) block, this block is standard HTML with Net.Data macro statements to substitute variables and a function call. Again the page_title variable is substituted into the title statement. And, as before, this block contains a function call. In this case, it calls the function rexx1 and passes to it the contents of the variable input_data, which it received from the form defined in the Input block. You can pass any number of variables to and from a function. The function definition specifies the number and the usage of variables that are passed.