BaCon CGI POST Command
Dec 22, 2013 16:14:40 GMT 1
Post by packetteer on Dec 22, 2013 16:14:40 GMT 1
Hi All
Thank you Bigbass for your Widgets4.bac BaCon program.
It taught me a lot about HTML form controls.
I have been programming Basic since the Vic-20.
This is wonderful.
For the first time I am participating
in a collaboration.
I took the liberty of modified your code by turning it
into HTML instead of BaCon. I then modified it by changing
POST to GET. (Also made minor changes to be more in the style
of how I manually write HTML.)
I did the above because I have a challenge for everyone
on this forum. The challenge is to take the following
HTML code and my updated cgiform.bac code and make it all
work with post instead of get.
You do not have to have separate HTML and BaCon code.
Anyway you want to solve the challenge is fine.
Of course your solution has to use BaCon.
This is the BaCon Forum after all.
Widgets4jb.html
I have also updated my Cgitest3.bac program.
I now call it cgiform.bac
I updated it to accept % signs in the form fields.
Thank you again Bigbass you are making this really fun.
John
Thank you Bigbass for your Widgets4.bac BaCon program.
It taught me a lot about HTML form controls.
I have been programming Basic since the Vic-20.
This is wonderful.
For the first time I am participating
in a collaboration.
I took the liberty of modified your code by turning it
into HTML instead of BaCon. I then modified it by changing
POST to GET. (Also made minor changes to be more in the style
of how I manually write HTML.)
I did the above because I have a challenge for everyone
on this forum. The challenge is to take the following
HTML code and my updated cgiform.bac code and make it all
work with post instead of get.
You do not have to have separate HTML and BaCon code.
Anyway you want to solve the challenge is fine.
Of course your solution has to use BaCon.
This is the BaCon Forum after all.
Widgets4jb.html
<HTML>
<HEAD>
<TITLE>An Example of Form Widgets</TITLE>
</HEAD>
<BODY>
<H1>An Example of Form Widgets</H1>
<form method="get" action="/cgi/cgiform.bin">
<PRE>
Programming language: <input type=text name=language value=BaCon>
<br>Comments:
<textarea name="comments" rows="5" cols="20"></textarea>
<br>Rate the coolness:
<label><input type="radio" name="coolness" value="cool" />cool</label>
<label><input type="radio" name="coolness" value="very cool" />very cool</label>
<label><input type="radio" name="coolness" value="ice cold" checked=checked />ice cold</label>
<br>I will learn more about BaCon and CGI:
<label><input type="checkbox" name="learnmoreYes" value="yes" checked=checked /> Yes</label>
<label><input type="checkbox" name="learnmoreNo" value="no" /> No</label>
<br>I will use this operating system:
<select name= "operating_system" size="1">
<option value="Linux">Linux</option>
<option value="Solaris">Solaris</option>
<option value="HPUX">HPUX</option></select>
<br>My favorite animal(s):
<select name="animal" size="3" multiple="multiple">
<option value="Penguin">Penguin</option>
<option value="Camel">Camel</option>
<option value="Llama">Llama</option>
<option value="Panther">Panther</option></select>
<br>
<input type="submit">
<input type="reset">
</form>
</BODY>
</HTML>
I have also updated my Cgitest3.bac program.
I now call it cgiform.bac
I updated it to accept % signs in the form fields.
REM cgiform.bac
REM Using Bigbass Widgets4 form demo
REM By John KB2SCS Software Inc
REM 12/22/2013 MIT License
PRINT "Content-type: text/html"
PRINT ""
PRINT "<HTML>"
PRINT "<HEAD>"
PRINT "<TITLE>Cgi BaCon Bigbass Widgets4 form Test</TITLE>"
PRINT "</HEAD>"
PRINT "<BODY>"
OPTION BASE 1
LOCAL diminputs
LOCAL dimanswers
FUNCTION ConVert$(STRING Field$)
IF INSTR(Field$,"+") <> 0 THEN
Field$ = REPLACE$(Field$,"+"," ")
END IF
WHILE INSTR(Field$,"%")
Sholdbeg$ = MID$(Field$,1,INSTR(Field$,"%")-1)
Sholdend$ = MID$(Field$,INSTR(Field$,"%")+1)
IF LEFT$(Sholdend$,2)="25" THEN
Schar$="@@@PERCENTSIGN@@@"
ELSE
Schar$ = CHR$(DEC(LEFT$(Sholdend$,2)))
END IF
Field$=Sholdbeg$ & Schar$ & MID$(Sholdend$,3)
WEND
IF INSTR(Field$,"@@@PERCENTSIGN@@@") THEN
Field$ = REPLACE$(Field$,"@@@PERCENTSIGN@@@","%")
END IF
RETURN Field$
END FUNCTION
SPLIT GETENVIRON$("QUERY_STRING") BY "&" TO arrayinputs$ SIZE diminputs
FOR i = 1 TO diminputs
SPLIT arrayinputs$[i] BY "=" TO arrayanswers$ SIZE dimanswers
answer$=ConVert$(arrayanswers$[2])
'With each pass of the loop answer$ will
'contain the users answer to each of your forms fields. At this point you
'can do processing on the users answers. This is a demo program so no
'processing is done on the users answers all the next line does is display
'the users answers on a new HTML page.
'Since there is only one field per loop acquired then an array holding
'all the forms user answers seems the right way to go.
'That will be my next update to this cgifrom.bac program
PRINT answer$,"<br>"
NEXT
PRINT "</BODY>"
PRINT "</HTML>"
Thank you again Bigbass you are making this really fun.
John