Solved

How to pass variables to a page from a form and perl/cgi at the same time

Posted on 2003-11-04
6
1,541 Views
Last Modified: 2013-12-25
I have a page that's dynamically generated by cgi and I pass variables to the next page with a link like this

generate_next_page.cgi?val1=$value1&val2=$value2

where $value1 and $value2 are variables within my cgi page.

The problem is that on one page I also have a form that gathers new variables and I want to pass my original variables ($value1 and $value 2) as well as the new variables that are picked up from the form.

I've tried this a few different ways and I either get my old variables in the url, or the new ones, but never both at the same time.   Any ideas?

Thanks

 
0
Comment
Question by:rezachar
[X]
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
6 Comments
 
LVL 5

Accepted Solution

by:
djplaistow earned 84 total points
ID: 9679521
The variables can not have the same names. The variable name must uniquely identify the variable.

I am not one hundred persent sure that I understand your question, so part of this is a guess. Instead of using a link to maintain the old variable's value, use hidden variables within the form itself. The perl might look like this:

print <<END_OF_TEXT;
 <form name=yourForm method=post action="generate_next_page.cgi">

  <input type=hidden name=val1 value="$value1">
  <input type=hidden name=val2 value="$value2">
  New value 1:<input type=text name=newValue1 size=18>
  New value 2:<input type=text name=newValue2 size=18>
  <input type=submit name=pageSubmit>
 </form>
END_OF_TEXT

Now when the user selects the submit button, the old values come in as val1 and val2. The new values come to the script as newValue1 and newValue2. Of course if your page looks better with a link for the submit than a button, just  change the href's url to explicitly execute the JavaScript submit() method on the form. Incidently, the submit() method is the reason you should never name a submit button "submit" as is all too common.
0
 
LVL 8

Assisted Solution

by:inq123
inq123 earned 83 total points
ID: 9683709
Hi rezachar,

I think dj's solution basically solves most of your problem.  You just need to change the "post" method in the form to "get" if you want to have the variables displayed on the URL OR if you only handle GET variables.

As for JS, just use:

print "<a href=\"javascript:document.yourForm.submit()\">next page</a>\n";

in your program to submit the form above.

Cheers!
0
 

Assisted Solution

by:elsamman
elsamman earned 83 total points
ID: 9701350
The solutions mentioned above will work.  I assume what you are trying to do, however, is to pass your old variables in as parameters on the action URL to save space. I could never get that to work.  I have done this by passing them as extra parameters rather than variables and then parsing them.  

Form syntax:

<form action=foo.pl/parm1=value1/param2=value2>

I then just have a generic bit of Perl to stuff them back into CGI parameters

      my $path_info = $query->path_info;
      $path_info .= '/';
      $path_info =~ s/\+/ /;
      $path_info =~ s/[^\/A-Za-z\-_ 0-9=]//g;
      while ($path_info =~ /\/([A-Za-z\-_0-9]*)=(.*?)\//) {
            $query->param($1, $2);
            $path_info =~ s/\/$1=$2//;
      }

You may have to tweak this depending on the values you expect (I don't really unescape things properly in this example).
0
 

Expert Comment

by:Teh_Craze
ID: 9939734
Could allways try persistant data via cookies, and CGI::Session
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

751 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