Web Examples in Pick BASIC

Determining if Form Data exists in BASIC

SUBROUTINE FORMCHECK(FILELIST,ROOTLIST,FORMDATA, ENV, REPLY)
AM = CHAR(254); * Attribute Mark separates form fields
CRLF = CHAR(13):CHAR(10)
POST = 0; * Form data flag, assume not
*
* Cycle through environment variables
* looking for the REQUEST_METHOD variable
*
ENVCNT = DCOUNT(ENV,AM) - 1
FOR I = 1 TO ENVCNT
  IF ENV<I,1> = "REQUEST_METHOD" AND ENV<I,2> = "POST" THEN 
     POST = 1
  END
NEXT I
RETURN

 

Echoing Form Data back to Browser in BASIC

SUBROUTINE ECHO(FILELIST,ROOTLIST,FORMDATA, ENV, REPLY))
*
AM = CHAR(254); * Attribute Mark separates form fields
CRLF = CHAR(13):CHAR(10)
REPLY = ""; * Clear out old HTML code
*
* Show all fields as "name=value"
*
FCOUNT = DCOUNT(FORMDATA,AM) - 1
FOR I = 1 TO FCOUNT
  REPLY = REPLY:FORMDATA<I,1>:"=":FORMDATA<I,2>:"<BR>":CRLF
NEXT I
REPLY = REPLY:"</BODY></HTML>":CRLF
RETURN

 

Setting a Shopping Cart Cookie on Browser in BASIC

SUBROUTINE SETCART(FILELIST,ROOTLIST,FORMDATA, ENV, REPLY)
*
AM = CHAR(254); * Attribute Mark separates form fields
CRLF = CHAR(13):CHAR(10)
*
COOKIE = TIME()
REPLY = "Content-type: text/html":CRLF
REPLY = "Set-cookie: shoppingcart=":COOKIE:CRLF:CRLF
REPLY = REPLY:"<HTML><HEAD><TITLE>Setting A Cookie</TITLE>":CRLF
REPLY = REPLY:"</HEAD><BODY>":CRLF
REPLY = REPLY:"A Shopping Cart is now ready for you to shop with.":CRLF
REPLY = REPLY:"<BODY></HTML>"
RETURN

 

Retrieving The Shopping Cart cookie from Browser in BASIC

SUBROUTINE GETCARTNUM(FILELIST,ROOTLIST,FORMDATA, ENV, REPLY)
*
AM = CHAR(254); * Attribute Mark separates form fields
CRLF = CHAR(13):CHAR(10)
ALLCOOKIES = ""
COOKIES = ""; * Dynamic array of cookies
SHOPPINGCART = 0
*
* Cycle through environment variables
* looking for the HTTP_COOKIE variable
*
ENVCNT = DCOUNT(ENV,AM) - 1
FOR I = 1 TO ENVCNT
  IF ENV<I,1> = "HTTP_COOKIE" THEN ALLCOOKIES = ENV<I,2>
NEXT I
*
* Since all cookies are together, separate them out
* looking for the shoppingcart cookie
*
IF ALLCOOKIES NE "" THEN
  *
  * Separate the cookies by ";"
  CONVERT " " TO "" IN ALLCOOKIES; * Remove spaces
  SEMICOUNT = DCOUNT(ALLCOOKIES,";")
  FOR I = 1 TO SEMICOUNT
    COOKIE<I> = FIELD(ALLCOOKIES,";",I)
    IF COOKIE<I>[1,12] = "shoppingcart" THEN
       SHOPPINGCART = INDEX(COOKIE<I>,"=",2)
    END
  NEXT I
END
*
* Display results on browser of shoppingcart cookie
*
REPLY = "Content-type: text/html":CRLF:CRLF
REPLY = REPLY:"<HTML><HEAD><TITLE>Shopping Cart ID</title>":CRLF
REPLY = REPLY:"</HEAD><BODY>":CRLF
IF SHOPPINGCART THEN
  REPLY = REPLY:"<P>Your shopping cart number is ":SHOPPINGCART:CRLF
END ELSE
  REPLY = REPLY:"<P>No shopping cart number assigned":CRLF
END
REPLY = REPLY:"<BODY></HTML>"
RETURN