How to Process Inputs to a REBOL CGI Web PageProcessing HTML Forms in a REBOL Internet Based ApplicationJul 24, 2009 Mark Alexander Bain
Web Pages users normally pass information to applications by means of an HTML Form. The REBOL programmer can take those inputs and use them in their CGI scripts.
If a programmer needs to implement business rules across an organisation then REBOL is a suitable solution. The business rules can be mapped to a custom REBOL dialects and REBPOL itself is available in a number of versions, both free and commercial. For example anyone can download:
Therefore, if the programmer has access to a web server (such as Apache) then they can produce quickly produce REBOL CGI web pages for all of their users to view. Of course the next stage is for the developer to create REBOL CGI applications that can both display information for the users, and to accept information from them. For that to happen the REBOL must be able to process data sent from HTML forms. An Example HTML FormA user will enter information into an HTML form in a web page. The programmer must create such a form, for example: <form method=get action="\cgi-bin\process_input.r">
Enter your full name:<input name=full_name>
<input type=submit>
</form>
Here the form will call the "process_input.r" script file when the user clicks on the submit button. Identifying the Request Method with REBOLThere are two methods that the web programmer can use to send information from the form to the CGI application:
The CGI application must, therefore, be able to identify which method is being used and then to handle the inputs accordingly. The first step is to add the first three obligatory lines that must appear at the start of every REBOL CGI file. These lines are:
They will look like: #!C:\REBOL\rebcore -c
REBOL[]
print "content-type: text/html^/"
And, in this example, the request method being used is displayed in the browser: print system/options/cgi/request-method
Figure 1 (at the bottom of this article) shows the results when using the GET method, and figure 2 shows the results of using the POST method. The next step is to process the inputs according to the sending method being used. Processing the CGI Inputs with REBOLThe CGI variables will start life as a string, either read in from the string sent as part of the URL (in the case of the GET method) or it will be read in from the standard input (in the case of the POST method). The first step, therefore, is to create the variable that will store this information. In this case it's been given and initial size of 1 KB: cgi-string: make string! 1024
The CGI input is then read into this string: switch system/options/cgi/request-method [
"GET" [cgi-string: system/options/cgi/query-string]
"POST" [read-io system/ports/input cgi-string 1024]
]
At the moment the string is not in a usable form;
However, all of that can be resolved in a single statement: cgi: construct decode-cgi cgi-string
This new object (named "cgi") will contain a field for each of the CGI variables, for example: print [ "Hello" cgi/full_name ]
Figure 3 shows this simple process in operation, and that's the important thing for any programmer to remember: it is a very simple procedure, but it enables the REBOL programmer to create highly sophisticated business rules based applications.
The copyright of the article How to Process Inputs to a REBOL CGI Web Page in Computer Programming is owned by Mark Alexander Bain. Permission to republish How to Process Inputs to a REBOL CGI Web Page in print or online must be granted by the author in writing.
CommentsAug 25, 2009 8:15 PM
Guest :
1 Comment:
Related Articles
Related Topics
Reference
More in Technology
|