[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-Modules] Generating HTML Code via MacPerl



I have created a '.cgi' File which includes the partial Code below -

use CGI ':standard';

# print the HTTP Header and the HTML Document
print header,
     start_html('DPR209 AddressBook'),
     h1('DPR209 AddressBook');

     &Display_Form();    # Yes, the '&' is optional - jump to Function 
[Sub-Routine].
     &Display_Posts();   # Yes, the '&' is optional - jump to Function 
[Sub-Routine].
print end_html;

.
.
.

# HTML Form ...
# Display_Form - prints the MessageBoard Form.
sub Display_Form {
   my(%thelabel) = ("10"=>"10  ","20"=>"20  ","30"=>"30  ","40"=>"40 
","50"=>"50  ");
   print start_form,
     b(),
     p(),
     "Number of entries to show:",
     br(),
     radio_group(-name=>'radio_Button', -values=>['10','20','30','40','50'],
                 -default=>'10',, -labels=>\%thelabel),
     " ",
     submit(-name=>'show_Button', -value=>'Show Posts'),
     p(), "Enter Name:",
     br(),
     textfield(-name=>'sender',, -size=>20, -maxlength=>20),
     br(), "Submit a post:",
     br(),
     textfield(-name=>'submit',, -size=>20, -maxlength=>20, -override=>1),
     submit(-name=>'submit_Button', -value=>'Submit a Post'),
     br(), "Search all post:",
     br(),
     textfield(-name=>'search',, -size=>20, -maxlength=>20, -override=>1),
     submit(-name=>'search_Button', -value=>'Search Posts'),
     p(),
     hr(),
   end_form;


... and all works well.

I was able to figure out the br(), p(), and hr() Functions from an 
example or two [2] from 'Learning Perl' [O'Reilly].

What I cannot do is locate any Material [via Books, WebSites, Files 
suppied with 'MacPerl'] explaining br(), p(), hr() and the other HTML 
equivalent.
Using Shuck and looking at 'CGI.pm' was of no specific help.
Where is the 'use CGI ':standard';' to allow me to use the HTML 
equivalen Perl Functions?

I flipped through the 'CGI Programming' [O'Reilly] Publication and it 
too did not contain these specific Perl Functions.

-----

I also did an Assigment using this Format -

#GenerateHTML
#04 Novermber 2000
#MacPerl 5.1.0r2
#Version 1.0.0
#

# GenerateHTML - create a 'theDBF.html' File, which can be dragged 
onto any Browser Window - which will
#  display the latest List of Data Base entries.
sub GenerateHTML {
   my (@localDB) = @_;
   my($localName, $localCompany, $localPhone, $localFax, $localEMail);

   $theDBhtml = "theDBF.html";
   open (DATA, ">$theDBhtml") || die "Was not able to create the File: 
$theDBhtml" . "\n";

     print DATA "<html><title>DPR 209 DataBase Window</title>";
     print DATA "<h1>DPR 209 DataBase</h1><body>";

     print DATA "<table width=\"598\" border=\"2\" cellspacing=\"4\" 
cellpadding=\"0\">";
     print DATA "<tr>";
     print DATA "<td><b>Name</b></td>";
     print DATA "<td><b>Company</b></td>";
     print DATA "<td><b>Phone</b></td>";
     print DATA "<td><b>Fax</b></td>";
     print DATA "<td><b>Email</b></td>";
     print DATA "</tr>";

     @localDB = sort (@localDB);
     foreach (@localDB){
       ($localName, $localCompany, $localPhone, $localFax, 
$localEMail) = split (/:/, $_);

# 09 November 2000
# Ok, the if (){} below is a quick fix - until I can give the added 
'Blank Line' in the
#  'generated .html' File.   The 'GenerateHTML.pl' File is where I 
must concentrate. SJWL.
       if (&HandleBlanks($localName) ne "&nbsp;"){
         print DATA "<tr>";
         print DATA "<td>" . $localName . "</td>";
         print DATA "<td>" . &HandleBlanks($localCompany) . "</td>";
         print DATA "<td>" . &HandleBlanks($localPhone) . "</td>";
         print DATA "<td>" . &HandleBlanks($localFax) . "</td>";
         print DATA "<td>" . &HandleBlanks($localEMail) . "</td>";
         print DATA "</tr>";
       }
     }

     print DATA "</table></body></html>";

   close (DATA);
}

1;  #forced return Value - a must when using the 'require' function.

This I can do and figure out - but I like the first Format [listed 
first] and would prefer to use it over the second Format.

-----

Now I see Code like this (see below) [which does not run for me - I 
get an '404 Page not Found' or 'Internal Server Error' (as I putz 
with the Code)]

#!/usr/bin/perl

use CGI::Form;

$cgi_form = new CGI::Form;

print <<'End_of_Header';
     <HTML>
     <HEAD><TITLE>Watch This!</TITLE></HEAD>
     <BODY>
     <H1>Watch This!</H1>
End_of_Header

print $form->startform;

## Creates a text field

print "Name: ";
print $form->textfield('name'), "<BR>\n";

## Creates a group of radio buttons

print "<P>Where do you live: <BR>";
print $form->radio_group (-name      => 'where',
      -values    => ['North America',
       'South America',
       'Europe',
       'Australia',
       'Asia',
       'Antartica'],
      -default   => 'North America',
      -linebreak => 'true');

## Creates a textarea field

print "Comments: ";
print $form->textarea('comments', undef, 5, 40);

print "<P>";
print $form->reset;
print $form->defaults;
print $form->submit ('Send!', 'Submit');
print $form->endform;

print "</BODY></HTML>";


I am also interested in this Format - again prefered over the second 
Format, shown above.

Now I do not see a 'Form.pm' in my 'lib' Folder - perhaps a dumb 
Question or two; but, here it goes -
Do I need to specifically download it?,
if so - is there a MacPerl specific Version I need to know about, etc.?
Where to 'Base.pm' .... come into play?

-----

My understanding of the above -

There are, at least, three [3] Formats to generate an HTML Web Page 
in [Mac]Perl.

1)   print start_form .... ,
2)   print DATA "<table width=\"598\" border=\"2\" cellspacing=\"4\" 
cellpadding=\"0\">"  ......,
3)   print $form->startform .....

OK ok I did not have any 'form' Code in the second Example - but it 
is the format I am trying to convey here ...

So - and simply asked -
Where does one obtain specific Documentation listing all the 
Functions and their operations for each of the above displayed 
Formats?


I test my Code at 
'http://balder.prohosting.com/~mcpnph/cgi-bin/xxx.cgi' - where xxx is 
the Name of my CGI File, under test.
Code that works - 
'http://balder.prohosting.com/~mcpnph/cgi-bin/messageboard.cgi'


Thank you for your time and any assistance.

S. Leidy

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-modules-request@macperl.org