pass information from an input tag

Posted on 2003-03-10
Medium Priority
Last Modified: 2013-12-25
I would like to find out how to write and INPUT statment with in my CGI script

With in my cgi script I have a HTML form  that pass the information to a Payment processer.
I ahve this information

my cost$ = 12.95;
my $x_amount = $cost  * $quant

I would like to have and  input tag that would enter the value of $quant
so that when you hit the submit button it would write it to the $x_amount.
I ahve the following but does not send the information to $x_amount
print "<input type=\"value\" name=\"quant\" value=\"".$quant."\">\n";

Thank you
Question by:rcplan2u
  • 2

Accepted Solution

archaic0 earned 200 total points
ID: 8105261
To pass form input to your script you need to start with something like this:

     $i = 0;
     read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
     @pairs = split(/&/, $buffer);
     foreach $pair (@pairs)
          ($name[$i], $value[$i]) =
                  split(/=/, $pair);

          $value[$i] =~ tr/+/ /;
          $value[$i] =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

          $name[$i] =~ tr/+/ /;
          $name[$i] =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;


That sets all your form data to name/value pairs.  If you send two input types with your form:

<input type="text" name="one" value="bob">
<input type="text" name="two" value="sally">

Then the above will set four variables for you.  $name[0] will be "one", $name[1] will be "two, $value[0] will be "bob", and $value[1] will be "sally".

Remember that programming languages start with 0 as the first interger, not 1.

Then you can do what you want with that info later in the script.

Author Comment

ID: 8108821
can you tell me how i can use the input $value[0] in math.
Like having $x_amount  = $price *  $value[0]
which doesn't seem to work that way

Expert Comment

ID: 8109102
It should work as far as I know, but I usually assign those to local variables before working with them.

$quan = $value[0];
$price = $value[1];

$amount = ($price * $quan);


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

599 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