Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

HTML Tag attribute problems with CGI.pm

by Prince99 (Scribe)
on May 30, 2001 at 19:15 UTC ( [id://84285]=perlquestion: print w/replies, xml ) Need Help??

Prince99 has asked for the wisdom of the Perl Monks concerning the following question:

Hail brother monks,

I am trying to write a little perl script that makes use of CGI.pm and am having trouble understanding a couple of things. Here is what I have done so far:

#!/usr/local/bin/perl -w use strict; use CGI qw/:standard/; # load standard CGI routines my $query = new CGI; print $query->header(type=>'image/gif'); print $query->start_html(title=>'PMI Human Resources', author=>'berry-kelly@pmimail.com', meta=>{'keywords'=>'PMI HR HumanResources', 'copyright'=>'copyright 2001 Kelly Be +rry'}, style=>{'src'=>'style.css'}, BGCOLOR=>'blue'); print $query->start_form(method=>'post', action=>'editpositions.pl') +; print "What is the Job Title?"; print $query->textfield('JobTitle','',30,80); print "<br><br>What is the Date Listed?"; print $query->textfield('DateListed','',30,80); print "<br><br>What is the Job Description?<br>"; print $query->textarea('Description','',10,80);
As you can see this is not real difficult stuff, but I don't get the results I expect. According to the CGI docs:
"Any additional attributes you want to incorporate into the <BODY> tag(as many as you like). This is a good way to incorporate other Netscape extensions, such as backgroung color and wallpager pattern.

This code doesn't change the bgcolor, it just print BGCOLOR on my html page. Also is there a way to put a BACKGROUND image on the page? Any help would be appreciated...

Prince99 bangs his head against the wall in frustration.


Prince99
Too Much is never enough...

Edit by tye

Replies are listed 'Best First'.
(Ovid - cleaning up your CGI code) Re: cgi.pm problem
by Ovid (Cardinal) on May 30, 2001 at 20:14 UTC

    Since you have imported the standard CGI routines into the main namespace, you do not need to instantiate a CGI object and thus can use the function oriented method. I have rewritten this with that in mind. Also, all attributes for functions now have a dash "-" in front of them. I think the code below is much closer to what you are looking for.

    #!/usr/local/bin/perl -w use strict; use CGI qw/:standard/; # load standard CGI routines print header( -type => 'text/html' ), start_html( -title => 'PMI Human Resources', -author => 'berry-kelly@pmimail.com', -meta => { 'keywords' => 'PMI HR HumanResources' +, 'copyright' => 'copyright 2001 Kelly Be +rry' }, -style => { 'src' => 'style.css' }, -BGCOLOR => 'blue'), start_form( -method => 'post', -action => 'editpositions.pl' ), p( "What is the Job Title?" ), textfield( 'JobTitle', '', 30, 80), br, br, "What is the Date Listed?", textfield( 'DateListed', '', 30, 80), br, br, "What is the Job Description?", br, textarea('Description', '', 10, 80), submit, end_form, end_html;

    Look ma, no HTML!

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: cgi.pm problem
by larsen (Parson) on May 30, 2001 at 19:29 UTC
    mmm... I have problems with this line:

    print $query->header(type=>'image/gif');

    Looking at the rest of your post, it seems that this could be better:

    print $query->header(type=>'text/html');

      Originally, I had print $query->header(type=>'text/html'); but I was trying to load an image as the background and had tried the code posted. I didn't change it back before I posted it, sorry

      Prince99

      Too Much is never enough...
Re: cgi.pm problem
by neophyte (Curate) on May 30, 2001 at 19:39 UTC
    bgcolor is not really a tag, but an attribute to the body - tag, so you would have to put:
    ... -meta=>{'keywords'=>'PMI HR HumanResources', 'copyright'=>'copyright 2001 Kelly Berry'}, -style =>{'src'=>'../style.css'}, -bgcolor =>'blue'); ...

    into your code. (Warning: I have not tested that piece of code)
    But the body color attribute is already covered with CSS1, so you can put that in with your style-sheet.

    neophyte Niederrhein.pm

    updated: ah well, I never used cgi to create html, I just moved from here-docs to templates.
Re: cgi.pm problem
by arturo (Vicar) on May 30, 2001 at 19:59 UTC

    I usually do 'nonstandard' tags in start_html by prepending a - to their names, à la:

    print $query->start_html(-title=>"Hi there", -bgcolor=>'#ffffff');

    Yeah, title is standard but I do that for uniformity and to avoid getting odd results when a tag I think is a standard one isn't.

    HTH.

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'
Re: cgi.pm problem
by kiz (Monk) on May 30, 2001 at 21:18 UTC

    The HTML syntax has no real way of loading a background image directly, for this you need to use style-sheets.

    The answer is

    $c = CGI->new(); push @page, $c->header; push @page, $c->start_html( -style=>{-src=>'/style/st1.css'}) ... yada ...

    and in the file ..../style/st1.css you include the contents:

    BODY {background-image: /dir/image.png}

    This is untested. I'm sitting in someone elses house, so doing this from memory. If neccessary, look at the www.w3c.org web site for details on stylesheets

    -- Ian Stuart
    A man depriving some poor village, somewhere, of a first-class idiot.

      You don't have to use a stylesheet, you can just specify the url to use in start_html().
      start_html(-background=>'http://somewhere.com/img.gif');


      -Lee

      "To be civilized is to deny one's nature."
Re: cgi.pm problem
by Prince99 (Scribe) on May 30, 2001 at 21:14 UTC
    Thank you all for you great suggestions. This is what makes this place great...The quick and intelligent responses. PerlMonks rule
    Prince99

    Too Much is never enough...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://84285]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found