Image on a form in Perl

software development

#1

I seem to have forgotten everything I once knew about perl after several years of working in php instead. I just wanted to pretty up an input form in a perl script by adding a image of our logo. Here’s what I have been trying:

use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use File::Copy;


my $logo = ‘YKFPlogo.jpg’;
my $logo_url = ‘http://ykfp.org/cgi-bin/YKFPlogo.jpg’;



sub display_form {
print
start_multipart_form(-action => url ()),
"Submit your file to YKFP: ",
br (),
filefield (-name => $file_field, -size => 90),
br (),
submit (-name => $submit_field, -value => $submit_value),
br (),
br (),
print img ({-src => $logo_url});
end_form ();
return;
}

I made a copy of the logo jpg right in my cgi-bin directory with the script just so I wouldn’t be confused by path string syntax errors. I’ve tired both the url and the file name as the source, and tried syntax like print ", but all I ever see on the form is a “1” instead of the image.

This should be easy for you guys.

This signature line intentionally blank.


#2

Well, I already figured out I misspelled the logo file name. Now the logo appears on the form, but at the top not the end, and I still get the 1 at the bottom of the form.

This signature line intentionally blank.


#3

Drop the "print"s from your code. The CGI utility functions print stuff when you call them and return 1.


#4

Thanks, I’m back in business now.

I thought maybe I could center the image by adding the align=>CENTER to the form like
img ({-src => $logo_url,-align=>CENTER});

but I get the error: Bareword “CENTER” not allowed while “strict subs” in use. Is centering a different syntax or do I need to drop the use of strick? If I put CENTER inside double or single quotes, it runs but doesn’t change alignment.

This signature line intentionally blank.


#5

The align attribute on images affects vertical alignment, not horizontal alignment. If you want to horizontally align the image, you’ll have to wrap it in a center tag (or div align=center).


#6

That was not accurate. The functions return string values. He forgot that perl statements are terminated by semicolons.

print 1, 2;

Not only writes output but it also is successful and returns the value 1.

So if we pass a call to print as an argument to print…

print ‘a’, ‘b’, print ‘c’;

We end up with “cab1” because the arguments are evaluated then written as output.

Worse yet he had:

print ‘a’, ‘b’, print ‘c’; ‘d’;

And of course since ‘d’ wasn’t being passed in a call to print it did not get written as output.

Customer since 2000 :cool: openvein.org | Please don’t feed the trolls. :@


#7

Badurrr! My bad - you’re entirely correct.