I'm trying to make a CGI script that will take two form fields and let a user enter in an unlimited amount of data points. For instance they will select a city and distance, then a second city and distance, then a third... etc..

You can see by executing my code what I'm trying to do, I just can't get the values from one submission to another to stay.

Any ideas?
#!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use strict; use CGI; my $cgi = CGI->new(); my $city1 = $cgi->param("city"); # Get a fresh warning point my $distance1 = $cgi->param("distance"); my @parameterNames = $cgi->param; my $numCity = 0; #Counter for all the Cities passed back to the scrip +t foreach(@parameterNames){ if(/city/) { #Check each paramater to see if is a "city" is present $numCity++; #If it is a city, add it to the counter } } print $cgi->header; my $action = "help.pl"; print $cgi->start_form(-action=>$action); my $quit = '1';#Once this # gets high enough, the loop "quits" if ($numCity){ #If there are any cities, print them as hidden fields while($quit <= $numCity) { # my $hiddenCity = "\$city".$quit; # my $hiddenCityValue = eval $hiddenCity; # my $hiddenDistance = "\$distance".$quit; # my $hiddenDistanceValue = eval $hiddenDistance; my $hiddenCityName = "city".$quit; my $hiddenDistanceName = "distance".$quit; my $hiddenCityValue = $cgi->param("$hiddenCityName"); my $hiddenDistanceValue = $cgi->param("$hiddenDistanceName"); print $cgi->hidden("$hiddenCityName", "$hiddenCityValue"); print $cgi->hidden("$hiddenDistanceName", "$hiddenDistanceValue"); print "$hiddenCityName => $hiddenCityValue<br>"; print "$hiddenDistanceName=> $hiddenDistanceValue<br><hr>"; $quit++; } } print <<EOF; <select name="city" tabindex="1"> <option value="1">Columbus</option> <option value="2">Chicago</option> </select> &nbsp&nbsp&nbspDistance:&nbsp<input type="text" name="circularWarningD +istanceStart" size="6" maxlength="6" /> <br> EOF print $cgi->submit('Go'); print $cgi->end_form;

In reply to Re^2: Printing Variable Variables by awohld
in thread Printing Variable Variables by awohld

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.