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,550 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

623 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