The implementation of the CGI engine is complete. My favorite feature works better (and faster) than it's predecesor's.
An HTML form, or portion of HTMl code (including javascript code) can be embedded like this:
#FORM MyForm, "someform.html"
You can double click the #FORM meta-command in the IDE and the HTML form opens for edition. These forms are added as a CGI resource that is then expanded at run time. It is then available via its variable token, in this case:
MyForm The HTML code in these forms can contain HTML code, or "tokens" (variable placeholders). For example the portion of HTML code contained in
MyForm could be:
Buyer: [!tkn.nombre]
Email: [!tkn.email]
Password: [!tkn.password]
Secret: [!tkn.secret]
The price is: [!price]
The variable tokens are composed by 3 parts:
- [! Opening bracket and exclamation symbol.
- body of the variable (can be an UDT with members and dimensions, only literals allowed, no operations).
- ] Bracket to close the token.
At runtime, the variables need to be declared with the token switch and then filled as normal:
#COMPILE CGI
#COMPILER OXYGEN
#PROJECT "nbson"
#OPTIONS X64 developer 'localtest
#DIM ALL
#DATABASE closed
#TIMELIMIT 10 ' Allow the script to run 10 seconds max.
#FORM MyForm, "someform.html"
TYPE UserDt EXACT
nombre as String
email as string
Password as string
secret as string
END TYPE
FUNCTION PBMAIN() AS LONG
DIM price AS STRING TOKEN
DIM Tkn AS UserDt TOKEN
price = "$ 499.95"
Tkn.Nombre = "Brian Alvarez"
Tkn.Email = "basictophp@hotmail.com"
Tkn.Password = "********"
Tkn.Secret = "Its called secret for a reason!"
CALL FormOut(myform)
END FUNCTION
Finally, the FormOut() function merges and outputs the HTML form with the contents of the token variables. Here is a sample output:
view-source:http://www.nbson.com/test/tokens.exe
If you need to merge the tokens of a string, without outputting the results to the browser, you can use ProcStr().
The UDT tokens make use of the internal system of dimensions, so, it is important that you use the same dimension as the one in the declaration, for example when you declare an UDT member element with, let's say, like this:
ustElem(-10 to 10) as string
Tokens variables are almost identical to the normal ones, they are very versatile and you can use token variables as normal, passing them byref, byval, getting STPTR addresses from them, the usual. However, it is recommended to use them only for output and not for speed-critical tasks, because there is a slight impact on performance.
Token variables can be merged to an HTML variable only inside the module they were declared in. If you pass a token variable to another module as a parameter, and you try to merge it with an HTML form, it wont work.
By the way, the forms embedded with #FORM, are also tokens, so, you can embed them in another HTML tokens as well.
This is only one of the features of CGI scripts in Oygen, but there are many more, like urlencode, urldecode, entityencode, entitydecode, base64_encode, base64_decode, rc4, md5, automated header handling, automated form parsing, file-uploading features, cookie system, session system, database system, URI parsing... and more.
Working with CGI in PluriBASIC + Oxygen is very satisfactory.