Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-11-04
6
Medium Priority
?
1,556 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 336 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 332 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 332 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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 focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

705 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