For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > May 2004 > html in perl









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author html in perl
Stu

2004-05-22, 11:31 am

I have an html page that calls a perl routine to parse input into a
file. After the perl routine is completed I want to display some html
back to the user. How can I do it. I thought I could use this
routine in the original html page that calls my perl script.

<form action="Scripts/Standard.pl" method="post">
<input type="hidden" name="redirect"
value="/Inetpub/wwwroot/ThankYou.htm">

but that doesn't display ThankYou.htm back so can I put the html in
the perl script? If so what do I need to do...thanks in advance..
Michael Capone

2004-05-22, 11:31 am

stu@freedomfundinggroup.com (Stu) wrote in message news:<fa19c87f.0404051109.536aedbe@posting.google.com>...
> I have an html page that calls a perl routine to parse input into a
> file. After the perl routine is completed I want to display some html
> back to the user. How can I do it. I thought I could use this
> routine in the original html page that calls my perl script.
>
> <form action="Scripts/Standard.pl" method="post">
> <input type="hidden" name="redirect"
> value="/Inetpub/wwwroot/ThankYou.htm">
>
> but that doesn't display ThankYou.htm back so can I put the html in
> the perl script? If so what do I need to do...thanks in advance..


There are two solutions to the problem:

1. Put the HTML directly into the perl script, as you suggested, or
2. Redirect the browser to Thankyou.htm (which, it appears, is what
you'd prefer to do).

#2 is probably the most straightforward; first, get rid of the hidden
field above. We'll let perl do that for us.

Your perl script will run as usual; make sure it does not print any
output. Once the processing is completed, add the following line:
print "Location: /ThankYou.htm\n\n";

This will cause the browser to redirect and display the ThankYou.htm
page.

Added bonue: something like this would be preferrred:

if ($error)
{
print "Location: /Error.htm\n\n\n";
}
else
{
print "Location: /ThankYou.htm\n\n";
}

Now, later on, it's not going to be practical to simply redirect;
you'll want to show customized html output. You can do it like so:

#!/usr/local/bin/perl

# lots of processing here
# and more processing

print "Content-type: text/html\n\n";
print <<ENDHTML;

<HTML>
<BODY>
Dear $name, <BR><BR>
Thank you for filling out my form. You'll be hearing from me
shortly.
</BODY>
</HTML>
ENDHTML

############

Good luck!

MAC
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com