Getting Variables From A Form

They have: 4 posts

Joined: Dec 1999

I'm new to CGI, and would like to know how to get variables from a form. I have used the name of the object in the HTML form, but it doesn't seem to work. Any suggestions?

They have: 850 posts

Joined: Jul 1999

I will give you an example of what I do.

<form action="/cgi-bin/script.cgi" method="POST">
<input type="text" name="email">
<input type="text" name="name">
<input type="submit" value="GO">
</form>

Than at the start of the script I have:

Code Sample:

&GetFormInput;


sub GetFormInput {

(*fval) = @_ if @_ ;

local ($buf);
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
}
else {
$buf=$ENV{'QUERY_STRING'};
}
if ($buf eq "") {
return 0 ;
}
else {
@fval=split(/&/,$buf);
foreach $i (0 .. $#fval){
($name,$val)=split (/=/,$fval[$i],2);
$val=~tr/+/ /;
$val=~ s/%(..)/pack("c",hex($1))/ge;
$name=~tr/+/ /;
$name=~ s/%(..)/pack("c",hex($1))/ge;

if (!defined($field{$name})) {
$field{$name}=$val;
}
else {
$field{$name} .= ",$val";


}


   }
}
return 1;
}

$inputemail = $field{'email'} ;
$inputname = $field{'name'} ;

Than whatever was inside the email <input box> would be in the variable $inputemail, and whatever was in the name <input box> would be in $inputname

------------------
A 'jiffy' is an actual unit of time for 1/100th of a second.

They have: 4 posts

Joined: Dec 1999

Ok, thanks.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.