Author Topic: CGI engine is complete.  (Read 1479 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
CGI engine is complete.
« on: August 24, 2019, 02:53:28 PM »
 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:

Code: [Select]
#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:

Code: [Select]
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:

Code: [Select]
#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:

Quote
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:

Code: [Select]
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. :)



JRS

  • Guest
Re: CGI engine is complete.
« Reply #1 on: August 24, 2019, 05:53:49 PM »
Quote from: Jose@JRS
How are they going to sell a converter that uses an alpha compiler as the backend?

Probably easier then using a compiler only the dead author could build.

Brian Alvarez

  • Guest
Re: CGI engine is complete.
« Reply #2 on: August 24, 2019, 08:30:44 PM »
PluriBASIC learned from that mistake. It is prepared to allow others to modify the core features. In fact, i would encourage others to do so!! i am making the basics with it, but i would like to see others improve my code!

 For example, right now the DIALOG statement creates windows using CreateWindowEx, so, DIALOG UNITS is still not working (only DIALOG PIXELS). But the engine is prepared to allow others to modify the core code for DIALOG NEW statements (see screenshot attached), in order to allow others to enhance the statement even for DPI aware dialogs! :)