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
Solved

Perl Form Vars

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

808 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