Passing values from html to a perl script

<<$Value= $FORM{‘Familia’};>>

For getting your value like this you should parse the form.

here i am writing an example showing how you can parse value from a form using POST Method.

#############
# Parse form

read(STDIN, $buffer, $ENV{‘CONTENT_LENGTH’});

#read the values from envourment variable .store in buffer.

@pairs = split(/&/, $buffer);

#split that buffer value

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

#separate name and values from the pair.

$value =~ tr/+/ /;
#remove all the + from value..
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(“C”, hex($1))/eg;
$value =~ s/<!–(.|n)*–>//g;
$value =~ s/<([^>]|n)*>//g;
$FORM{$name} = $value;
#assain all the value to name..
}
##############

now you can get the value like this.

$Value= $FORM{‘Familia’}

##############——-############-###########–

If you you can use cgi.pm module you can get the input very easily.
see this example..

test.htm

<form method=”post” action=”test.cgi”>

<select name=”Familia”>

<select size=”1″ name=”Familia”>
<option selected value=”one”>one</option>
<option value=”two”>two</option>
<option value=”three”>three</option>
</select>

<input type=”submit” name=”submit” value=”submit”>
</form>
test.cgi

#!/usr/perl/bin

use CGI;
#use CGI.pm module

$q=new CGI;
$value=$q->param(‘Familia’);

#get the parameter from name field
# and store in $value variable.

print $q->header;
#print the header
print “<html>n”;
print “<head><title>Test</title></head>n”;
print “<body>n”;

print “<h1>Testing form input</h1>n”;
print “<b>Selected value is: “.$value.”</b>n”;

#just call the $value varable here.
print “</body>n”;
print “</htm>n”;

Reference: http://forums.devshed.com/perl-programming-6/passing-values-from-html-to-a-perl-script-7977.html

Leave a Reply