Solved

CGI problem (Help!!)

Posted on 2002-05-28
3
189 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
[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
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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.

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