Solved

Perl Form Vars

Posted on 2002-07-25
5
191 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Automating a script for user accounts LINUX 14 73
Folder Permission Powershell 4 57
Download a website to hdd 2 68
Interactive Script in Scheduled Task not running 8 31
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

821 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