HSM - Interaction with Forms

Product: Strategi
Modified Date:


One of the most common uses of HSM and web applications involve some sort of user input using HTML forms. This can be as basic as standard field entry to creation of dynamic form elements based on variable data returned from the HSM server. The following examples attempt to illustrate these concepts.

Simple Form Entry
The most basic use of forms involves one HTML page containing a form and a HSM file used to process the form data by passing to a HSM server and actioning the reply from the HSM server appropriately. This example will implement one HTML form allowing a user to enter their name and account number, a HSM file to send the data to a HSM server, which replies with an account balance.

<!-- HTML FILE USER_ENTRY.HTM -->
<HTML>
<BODY>
<form action="getbalance.hsm" method="POST" name="MAIN">
Enter Name
<input type="Text" name="USERNAME">

Enter Account Number
<input type="Text" name="ACCOUNT">

<input type="Submit" name="SUBMIT" value="Submit">
</form>
</BODY>
</HTML>


; HSM FILE GETBALANCE.HSM
; Server ACCOUNTS will accept the value of form field USERNAME
; from positions 1-40 and the value of form field ACCOUNT
; from positions 41-80. Although reply is up to the design of
; the server, in this case a return opcode of GETBAL will
; be returned if the account balance was successfully retrieved
; and substitute to page ACCOUNT_BALANCE.HTM to display the
; results using positions 1-10 of the reply data for HSM
; variable BALANCE. Any other opcode return could indicate a
; error condition or a page to request additional information.

[SERVER REQUEST]
server=ACCOUNTS
opcode=GETBAL
start_length_field=1,40,USERNAME
start_length_field=41,16,ACCOUNT

[REPLY]
opcode=GETBAL
start_length_field=1,10,BALANCE
; export previous form variables to retain values
export_field=USERNAME
export_field=ACCOUNT
substitute_url=account_balance.htm

[REPLY]
; if the server returns another opcode maybe due to error then
; redirect appropriately (used for illustrative purpose only)
opcode=*OTHER
assign_field_value=RPYOPC,*REPLY.OPCODE
start_length_field=1,9999,RPYDTA
substitute_url=other.htm


<!-- HTML FILE ACCOUNT_BALANCE.HTM -->
<HTML>
<BODY>
User <HSM NAME=USERNAME><BR>
Account <HSM NAME=ACCOUNT><BR>
;<BR>;<BR>
Your Account Balance is $<HSM NAME=BALANCE>
</BODY>
</HTML>
Dynamically Populating Form Elements
For pages that require dynamic form element generation such as custom list boxes, the use of HSM repeat blocks coupled with the data returned from the HSM server can be used to populate the form element appropriately. This example will use the same basic form as above to obtain basic user information but the resulting page will display a HTML file which is another form with a listbox giving the user the different balances to display which were returned from the HSM server.

<!-- HTML FILE USER_ENTRY.HTM -->
<HTML>
<BODY>
<form action="getbalance.hsm" method="POST" name="MAIN">
Enter Name
<input type="Text" name="USERNAME">

Enter Account Number
<input type="Text" name="ACCOUNT">

<input type="Submit" name="SUBMIT" value="Submit">
</form>
</BODY>
</HTML>


; HSM FILE GETBALANCE.HSM
; Server ACCOUNTS will accept the value of form field NAME
; from positions 1-40 and the value of form field ACCOUNT
; from positions 41-80. Although reply is up to the design of
; the server, in this case a return opcode of GETBAL will
; be returned if the account balance was successfully retrieved
; and obtain the different balances available for the user.
; The user will then be directed to SELECT_BALANCE.HTM to choose
; the appropriate balance to display.

[SERVER REQUEST]
server=ACCOUNTS
opcode=GETBAL
start_length_field=1,40,USERNAME
start_length_field=41,16,ACCOUNT

[REPLY]
opcode=GETBAL
start_length_field=1,10x10,BALANCE_ARRAY
start_length_field=101,10,NUM_BALANCE
; export previous form variables to retain values
export_field=USERNAME
export_field=ACCOUNT
substitute_url=select_balance.htm

[REPLY]
; if the server returns another opcode maybe due to error then
; redirect appropriately (used for illustrative purpose only)
opcode=*OTHER
assign_field_value=RPYOPC,*REPLY.OPCODE
start_length_field=1,9999,RPYDTA
substitute_url=other.htm

[BLOCK]
name=LIST_BALANCES
repeat_count=NUM_BALANCE


<!-- HTML FILE SELECT_BALANCE.HTM -->
<HTML>
<BODY>
<form action="getdetail.hsm" method="POST" name="MAIN">

User <HSM NAME=USERNAME><BR>
Account <HSM NAME=ACCOUNT><BR>

;<BR>;<BR>

Select Account Balance
<select name="BALANCE">
<HSMBLOCK NAME=LIST_BALANCES>
<option value="<HSM NAME=BALANCE_ARRAY>"><HSM NAME=BALANCE_ARRAY></select>
</HSMBLOCK>
<input type="Get Detail" name="SUBMIT" value="Submit">
</form>
</BODY>
</HTML>

...

HSM file getdetail.hsm would then request the balance detail
for a selected balance after the user submits the form.
Summary
Although these are basic examples of common operations, use of repeat blocks, block conditioning, *INDEX special values, and other form related items found in the HSM Guide allow the user to create both static and dynamic form content.

** End of Technical Support Bulletin **