Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML commands in perl code 2

Status
Not open for further replies.

JennyW

Technical User
Joined
Mar 1, 2001
Messages
323
Location
CA
Hiee!

I have a [tt]perl/.cgi[/tt] question regarding my mailing list.

When I enter an email address in my mailing list’s [tt]Form[/tt] I receive one of seven .cgi generated messages.

The problem is I don’t like where the message is located on the browser window.

Here’s my url…


Now, press the GO! Button. You don’t have to enter anything, you’ll get a message.

Now, you should see a few lines of text (please ignore the yellow text it’s not cgi generated).

I don’t like where the text is located. I would like it to be further away from the left side of the browser window. I don’t want it centered, I just want to move it to the right a ‘lil bit.

In the code, I tried applying a [tt]<font>[/tt] tag (below) within the [tt]print[/tt] line.

I applied the following [tt]<html>[/tt] (in purple) to the [tt]print[/tt] line…

[tt]print &quot;<font color=&quot;#000000&quot;>iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii</font>
<h2>Unable to subscribe your email address<h2>\n&quot;; [/tt]

The background of my page is black, which is why I made the i’s black. I thought that would push the [tt]Unable to subscribe your email address[/tt] line over a bit, but it didn’t. When I did this my script wouldn’t work. My browser displayed Internal Server Error. I took the font tags out and the script worked again.

Does anyone know how I can move the .cgi generated text away from the left side of the browser window?

I know that was a lot to read, but thanks for giving it your time,
Jenny
 
The reason you had an Internal Server Error was because you tried to nest double quotes (&quot;). Quotes are used by Perl in this instance to identify what is the HTML to be printed out, and what is supposed to be more Perl code. If you need double quotes inside the text that Perl is processing, you need to escape it with a backslash:

print &quot;<font color=\&quot;#000000\&quot;>iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii</font>&quot;;

However, if you want to have correct HTML, you shouldn't use a black font over a black background as a spacer. Use the special HTML character &quot;&amp;nbsp;&quot; for a spacer:

print &quot;<font color=\&quot;#000000\&quot;>
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;</font>&quot;;

Even better yet, use the &quot;x&quot; operator to handle the number of repeated spaces:

print &quot;<font color=\&quot;#000000\&quot;;
print &quot;&amp;nbsp;&quot; x 54;
print &quot;</font>\n&quot;;

As you have probably guessed, the x operator repeats whatever precedes it by the number specified after it; in this case, you are printing the HTML space character 54 times. This method makes it easy to change the number of spaces whenever you want. I have also added the &quot;\n&quot; at the end, so you will have a line break in your HTML output after that. This makes no difference to the browser, but makes your HTML output more readable when you View Source in the browser.
 
Hi rycamor and others,

I can’t seem to get the following code working properly in my .cgi script.

[tt]print &quot;<font color=\&quot;#000000\&quot;;
print &quot; &quot; x 54;
print &quot;</font>\n&quot;;[/tt]


How do I put the above code in my script? I can’t seem to get it to work.

This is how I put the code above in my script (I was unsuccessful)…
[tt]


if ($form{'address'}=~ tr/;<>*|`&$!#()[]{}:'&quot;//) {
&dheader;

print &quot;<font color=\&quot;#000000\&quot;;
print &quot; &quot; x 54;
print &quot;</font>\n&quot;;

print &quot;<h2><i>Unable to subscribe your email address</i></h2>\n&quot;;
print &quot;Please don't use weird symbols<br>\n&quot;;
&dfooter;
exit;
}
[/tt]

I’m trying to add spaces in front of the following lines of text…
[tt]
print &quot;<h2><i>Unable to subscribe your email address</i></h2>\n&quot;;
print &quot;Please don't use weird symbols<br>\n&quot;;
[/tt]

Does anyone know where I’m going wrong?

Thanks,
Jenny
 
In your first print statement, you've escaped the last quotation mark, so that statement never closes. It should end with a \&quot;&quot;; In fact, because all you're printing within the <font> tags are spaces, you don't need to have the font tags at all.

There is one more solution that I'd like to bring up that would eliminate the need for the non-breaking spaces that unnecessarily bloat the HTML. The solution consists of two style attributes, &quot;position&quot; and &quot;left&quot;, which can be given to a <p> (paragraph) element that surrounds your error message. This should work in any of the version 4+ browsers:
Code:
print qq(
<p style='position:relative;left:200px'>
<h2><i>Unable to subscribe your email address</i></h2> 
Please don't use weird symbols</p>
);
You can adjust the number proceeding left: to give yourself a wider or thinner margin.

Hope this helps.

brendanc@icehouse.net
 
Sophisticate is right, in principle, but I think you are better off with:
Code:
print qq(
<div style='position:relative;left:200px'>
<h2><i>Unable to subscribe your email address</i></h2> 
Please don't use weird symbols</div>
);

Style attributes are much more widely supported in the <div> tag. I even had trouble getting <p style='position:relative;left:200px'> to work in IE5.
 
Hi guys!!

Ok, so just to clarify, should the following code…
[red]
print qq(
<div style='position:relative;left:200px'>
<h2><i>Unable to subscribe your email address</i></h2>
Please don't use weird symbols</div>
);[/red]

…be added to my document like this?..

[tt]
if ($form{'address'}=~ tr/;<>*|`&$!#()[]{}:'&quot;//) {
&dheader;
[red]
print qq(
<div style='position:relative;left:200px'>
<h2><i>Unable to subscribe your email address</i></h2>
Please don't use weird symbols</div>
);[/red]
&dfooter;
exit;
}
[/tt]

=============================

Also,

Sophisticate, regarding this code…
[tt][red]
print &quot;<font color=\&quot;#000000\&quot;;[/tt]
print &quot; &quot; x 54;[tt]
print &quot;</font>\n&quot;;
[/red][/tt]
you wrote…

In fact, because all you're printing within the <font> tags are spaces, you don't need to have the font tags at all.

So, if I add the following code…
[red]
print &quot; &quot; x 54;[/red]

in my perl doc, like this…
[tt]
if ($form{'address'}=~ tr/;<>*|`&$!#()[]{}:'&quot;//) {
&dheader;[/tt]
[red]
print &quot; &quot; x 54;[/red][tt]
print &quot;<h2><i>Unable to subscribe your email address</i></h2>\n&quot;;
print &quot;Please don't use weird symbols<br>\n&quot;;
&dfooter;
exit;
}[/tt]

Then I will be able to enter the number of desired spaces I want?

Thanks guys!
Jenny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top