
fashimpaur
User
/ Moderator
Sep 7, 2000, 4:51 AM
Post #2 of 3
(148 views)
|
|
Re: Making a script web readable
[In reply to]
|
Can't Post
|
|
Yim11, First, you need to get the form variables from the CGI Environment on the server. Then, make your calculations and print the output in HTML back to the client browser. Here is a simple example: 'HTML FORM' <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> <HTML><HEAD><TITLE>Break Calculations</TITLE></HEAD> <BODY> <FORM method=POST action="cgi-bin/breakwages.pl"> Hourly Wage <INPUT type="text" name="wages"><br> Minutes on Break <INPUT type="text" name="minutes"><br><br> <INPUT type="submit" name="btnSubmit" value="Calculate"> </FORM> </BODY> </HTML> </pre><HR></BLOCKQUOTE> Then write a perl script something like this: breakwages.pl <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> #!/usr/local/bin/perl use CGI; $q = new CGI; $wages = $q->param('wages'); $minutes = $q->param('minutes'); $earnings = ($wages/60)* $minutes; print $q->header('text/html'); # edited here, forgot 'print' $htmlOut = qq~ <HTML> <HEAD> <TITLE>Wages On Break</TITLE> </HEAD> <BODY> You earned $earnings while you were on break! </BODY> </HTML>~; print $htmlOut; exit; </pre><HR></BLOCKQUOTE> That is the gist of doing CGI interaction with a web form. HTH, Dennis [This message has been edited by fashimpaur (edited 09-07-2000).]
|