Solved

Perl Form Vars

Posted on 2002-07-25
5
185 Views
Last Modified: 2013-12-25
I am learning PErl and am trying to figure out how to grab form posted variables.

I have the following page

***************************************************

sub printHTML
{
  print "<h3>This is a test Perl Script</h3>";
  print "<form method=post action=Default.pl>";
  print "<p>Enter your Firstname <input type=text name=Firstname></p>";
  print "<p>Enter your Surname <input type=text name=Surname></p>";
  print "<p><input type=submit></p>";
  print "</form>";
}

sub printHeader
{
  print "Content-type: text/html\n\n";
  print "<html>";
  print "<head><title>Test Page</title>";
  print "</head>";
  print "<body>";
}

sub printFooter
{
  print "</body>";
  print "</html>";
}

use CGI;

printHeader;
printHTML;

#print "Caller = $ENV{'HTTP_REFERER'}<br /><br />";
#print "Server = $ENV{'SERVER_SOFTWARE'}<br /><br />";
#print "QueryString = $ENV{'QUERY_STRING'}<br /><br />";

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;
}

foreach $key (keys(%FORM))
{
    #print "$key : $FORM{$key}<br /><br />";
}

print "$FORM('Firstname')<br /><br />";

printFooter;

***************************************************

This works:

foreach $key (keys(%FORM))
{
    #print "$key : $FORM{$key}<br /><br />";
}

But this doesn't :

print "$FORM('Firstname')<br /><br />";


Any ideas?

Cheers

Dave
0
Comment
Question by:daveamour
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:majorspank
ID: 7178059
I would suggest checking out the man page for the 'CGI' library.  
http://www.univie.ac.at/cgi-demo/cgi-bin/showman.cgi?command=CGI

This will allow you to do things like:

$q = new CGI;
$first_name = $q->param('first_name');
print $first_name;
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7178561
> #print "$key : $FORM{$key}<br /><br />";
> But this doesn't :
> print "$FORM('Firstname')<br /><br />"

of corse not. It prints:

  Firstname : value-typed-into-form<br><br>

And what is the problem then?
0
 
LVL 1

Accepted Solution

by:
majorspank earned 25 total points
ID: 7178768
I notice in the second statement that you are using round brackets '()' instead of curly brackets '{}'.  Sorry, I don't know the proper term for the bracket types.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7179493
damn, didn't recognize the brackets ...
0
 
LVL 19

Author Comment

by:daveamour
ID: 7179548
Thanks, I need glasses I think :)

Dave
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now