file.cgi?title=Title_Goes_Here
and then in the content area using $title or $FORM{'title'}
so the title shows up at the title and header with out the _? (Right now I can't even get the title to show up in the title and header.)
#!/usr/bin/perl# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ s/"//g;
$value =~ s/_/ /g;
}
sub get_url_input {
}
if (%FORM) {
if ($FORM{title}) { $FORM{title} = $FORM{title}; }
}
{
print "Content-type: text/html\n\n";
print <<EOM;
<TITLE>$title or $FORM{'title'}</TITLE>
<H1>$title or $FORM{'title'}</H1>
CONTENT AREA
EOM
}
[code]
1) THE HTML FILE
<html>
<head>
<title>
Title sender
</title>
</head>
<body>
<br><br>
Enter your title
<FORM METHOD="POST" ACTION="title.cgi">
<INPUT TYPE="text" NAME="title" SIZE="15" MAXLENGTH="15">
<INPUT TYPE="SUBMIT" VALUE="set title">
</FORM>
</body>
</html>
2) THE CGI FILE
#!/usr/bin/perl
print "Content-type:text/html\n\n";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
$title = $FORM{title};
print "<html>\n";
print "<head>\n";
print "<title>$title</title>\n";
print "</head>\n";
print "<body>\n";
print "The title of my page is $title \n";
print "</body>\n";
print "</html>\n";
[\code]
P.S. I didn't test the CGI, so watch for typos.. ;0)
$temp = $ENV{'QUERY_STRING'};
($varname,$content) = split(/=/,$temp,1);
$var{'title'} =~ s/_/ /;
print "Content-type: text/html\n\n";
print <<EOM;
<TITLE>$var{'title'}<TITLE>
<H1>$var{'title'}</H1>
CONTENT AREA
EOM
As a side note - is there a particular reason you're using an underscore? If you use a + or the encoded space %20, any of a million read/parse routines will turn the title into plain text with spaces. Note the extra step is removed to sub out the underscore, and that it extracts the encoded data regardless of GET or POST.
file.cgi?title=Title+Goes+Here
or
file.cgi?title=Title%20Goes%20Here
(either will work)
#!/usr/bin/perl
%FORM = &query;
$title = $FORM{'title'}; #This is uneccessary
print "Content-type: text/html\n\n";
print <<EOM;
<TITLE>$title or $FORM{'title'}</TITLE>
<H1>$title or $FORM{'title'}</H1>
CONTENT AREA
EOM
}
sub query{
my $method = $ENV{'REQUEST_METHOD'};
my ($query_string,$pair,%query_hash);
$query_string = $ENV{'QUERY_STRING'} if $method eq 'GET';
$query_string = <STDIN> if $method eq 'POST';
return undef unless $query_string;
foreach $pair (split(/&/, $query_string)) {
($_qsname, $_qsvalue) = split(/=/, $pair);
$_qsname =~ s/[\+]/ /g;
$_qsname =~ s/%([\da-f]{2})/pack("C",hex($1))/ieg;
$_qsvalue =~ s/[\+]/ /g;
$_qsvalue =~ s/%([\da-f]{2})/pack("C",hex($1))/ieg;
$query_hash{$_qsname} = $_qsvalue;
}
return %query_hash;
}
Before anyone flames me, this was a copy/paste from an existing read parse, and I'm aware it crashes if the $ENV{REQUEST_METHOD} is undefined and there's no query string. :-)