[Xitami] CGI School

Marc Doigny xitami@lists.xitami.org
Sat, 08 Dec 2001 09:25:40 +0100


This is a multi-part message in MIME format.

--=====================_502598235==_
Content-Type: text/plain; charset="us-ascii"; format=flowed

At 08:11 8/12/01, you wrote:
>Scott,

[...]

>    PB comes with tools that parse form data very easily.  You basically use
>a string buffer to put the contents in, then strip off the variable values.
>To create the resulting page, you use a line similar to:

You normally don't need them.
Already done by Xitami.
Try it (source included, executable on my server).


>WriteCGI "<b>The result of your query " & Request$ & " is: " & ResultValue$
>& </b>"

Better still: simply open the output file and print to it.

That's all you actually need: NO SINGLE LINE MORE:

FUNCTION PBMAIN()                               ' main module is always 
named pbmain
     i = 1                                       ' execution begins here
                                                 ' Xitami creates a single 
temp name for
     OPEN ENVIRON$("CGI_STDOUT") FOR OUTPUT AS #3
                                                 ' the output file. You 
open it and
     PRINT #3, "<html><body><pre>"               ' write your html to it.
     a$ = ENVIRON$(i)                            ' This is a demo program. 
We iterate
     WHILE a$ <> ""                              ' over the complete 
environment and
         PRINT #3, a$; "<br>"                    ' print it out. Whenever 
ENVIRON$(i)
         i = i + 1                               ' gives you an empty 
string, we're done.
         a$ = ENVIRON$(i)                        ' You'll see all the named 
<input...>
     WEND                                        ' fields parsed in their 
respective name
     PRINT #3, "<hr>"
     OPEN ENVIRON$("CGI_STDIN") FOR INPUT AS #1  ' Xitami also gives you 
the complete
     WHILE NOT EOF(1)                            ' query string in a temp 
file. Here we
         LINE INPUT #1, a$                       ' simply open that file 
and output it
         PRINT #3, a$; "<br>"                    ' to the output file.
     WEND                                        ' Here we terminate the 
html output
     PRINT #3, "</body></html>"                  ' and end the program.
END FUNCTION                                    ' In this example, there is 
no error
                                                 ' trapping needed, the 
best thing to do
when an error occurs is to try to continue. The only error that can occur 
is a disk full.

Use a$ = REMAIN$(ENVIRON$(i), "=") to get only the value, not the complete 
equate.

ENVIRON$ can be used with named strings (when you know what you are looking 
for, that is when using form data or opening files provided by Xitami) or 
with an index (when you don't know what you are looking for).

This source can be optimised (using integer variables instead of floating 
point defaults and so on).

You can try this program out at <http://web.verfaillie.com/cgi-bin/env.exe>
Add query strings like you want 
<http://web.verfaillie.com/cgi-bin/env.exe?123ABC>

Or use a complete <form... > to call it. There is a sample one included 
with this mail.



------------------<Mailserver VERFAILLIE BAUWENS>------------------
Alle uitgaande mails gecontroleerd op virussen door onze mailserver
Virusdefinities dagelijks aangepast.  -<postmaster@verfaillie.com>-
--=====================_502598235==_
Content-Type: text/html; charset="us-ascii"
Content-Disposition: attachment; filename="GUEST.HTM"

<html><body>
<form ACTION="http://web.verfaillie.com/cgi-bin/env.exe" method="POST">
<p>Enter your information, please:</p>
<table border=1>
<tr><td width=50%>Name:</td><td width=50%><input type=text size=20 maxlength=256 name="Name"></td></tr>
<tr><td width=50%>How much do you like this web page?</td><td width=50%><select name="LikeFactor" size=1>
<option value="A whole lot ">A whole lot</option>
<option value="Alot">Alot</option>
<option value="so so">so so</option>
<option value="no comment">no comment</option>
<option value="yuck">yuck</option>
<option value="hated it">hated it</option>
</select></td></tr>
<tr><td>What's your browser?</td><td><input type=radio name="BrowserType" value="IE">Internet Explorer <input type=radio checked name="BrowserType" value="Netscape">Netscape <input type=radio name="BrowserType" value="Other">Other</td></tr>
<tr><td>Would you like for someone to contact you?</td><td><input type=checkbox name="Contact" value="ON">Yes I do!</td></tr>
<tr><td>Remarks:</td><td><textarea name="Remarks" rows=2 cols=20></textarea></td></tr>
</table>
<input type=submit name="Submit" value="Submit Information">
<input type=reset name="Reset" value="Reset">
</form>
</body></html>

--=====================_502598235==_--