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
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
  • 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

Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

Question has a verified solution.

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

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

752 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