954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to get form values using POST method?

All, I have a simple question.

What is the standard procedure for retrieving form values via POST method in a web form? Perl can be extremely awkward for web programming, I'd normally use something else, but in this case I need to use Perl for the CPAN module.

Anyway, back to the point, If I have a basic html form, how do I get the values out in verify_login?

<form name="login" action="$cgidir?action=verify_login" method="POST">
    <input type="text" name="user">
    <input type="password" name="pass">
    <input type="submit" name="login" value="Login">
</form>
nonshatter
Posting Whiz
377 posts since Nov 2009
Reputation Points: 39
Solved Threads: 63
 

<form name="login" action="$cgidir?action=verify_login" method="POST">

The above doesn't look right to me. To get it to work I put it in an html document like the following:

<html>
<header>
<title>Post form example</title>
</header>
<body>
<form name="login" action="/cgi-bin/verify_login" method="POST">
    <input type="text" name="user">
    <input type="password" name="pass">
    <input type="submit" name="login" value="Login">
</form>
</body>
</html>


Then your verify_login can read what the form POSTed by using the CGI module and its param method.

#!/usr/bin/perl
#/cgi-bin/verify_login
use strict;
use warnings;

use CGI qw(:standard);
my $cgi=new CGI; #read in parameters

print $cgi->header(); #print a header
print $cgi->start_html("Welcome"); #generate HTML document start
print "<h1>Welcome, ",$cgi->param('user'),". Your password is ",$cgi->param('pass'),"</h1></p>";
print "But I won't tell anyone.</p>";
print $cgi->end_html();#finish HTML document
d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159
 

Fantastic, thanks very much

nonshatter
Posting Whiz
377 posts since Nov 2009
Reputation Points: 39
Solved Threads: 63
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You