Solved

CGI problem (Help!!)

Posted on 2002-05-28
3
185 Views
Last Modified: 2013-12-25
In my CGI form (written in Perl), I have
TWO  "Submit" buttons and when pressed, they
call 2 different functions from within
the same CGI page.
The submit buttons have the values
of "Submit1" and "Submit2". When pressed,
"Submit1" repaints" the CGI page..
For example, At the main CGI page, users
are shown some "select" options.Now when
"Submit1" is pressed, it repents the screen
with new info selected by those "select"
options.

But the form as well contains a file upload
button. And this value is required/used when
the "Submit2" button is pressed. Problem
is, if user selects a file with the file
upload button and then clicks "Submit1",
Submit1 function CANNOT repaint the page
with the "previously chosen" file by the
file upload button this is because the
input type "file" does NOT have a "value"
parameter (so use of a hidden field does not
work).

Here is the code:
******
#! /usr/bin/perl
use CGI qw/:standard :html3/;
...header etc..
$action = param('go');
if ("$action" eq "Submit1")
{
do_Submit1();
}
elsif ("$action" eq "Submit2")
{
do_Submit2();
}
else
{
print_main_page();
}

sub do_Submit1
{
...get some parameter from the main page generated by
...print_main_page() function..
print "<input type=file name=myfile>";
##No "Value" that I can specify above although I have
##it's file information....
}

sub do_Submit2
{
...calls some external script.
}

sub print_main_page()
{
print "", start_form;
print "<select name=myname>";
print "<option value=....></optrion></select>";
print "<input type=file name=myfile>";

print "<input type=submit name=go value=Submit1>";
print "<input type=submit name=go value=Submit2>";
print "<input type=file name=myfile>";

end_form;
}

}

Please help.
-tooki
0
Comment
Question by:tooki
3 Comments
 
LVL 7

Accepted Solution

by:
yoren earned 100 total points
ID: 7041164
It's possible to do what you want, but it's not easy. The reason you can't set the filename directly is because that would be a security risk. You'll need to do it with a signed javascript that you set to run automatically, using the onLoad property of the BODY tag. The script will look something like this:

 function setfile() {
  netscape.security.PrivilegeManager.enablePrivilege('UniversalFileRead');
document.myform.myfile.value='file.txt';
}

Here's the signing tool you'll need:
http://developer.netscape.com/software/signedobj/jarpack.html#signtool1.3
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now