?
Solved

Perl Form Vars

Posted on 2002-07-25
5
Medium Priority
?
195 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 100 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

801 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