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
Solved

CGI problem (Help!!)

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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 …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

856 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