Solved

CGI problem (Help!!)

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
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 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…

744 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

12 Experts available now in Live!

Get 1:1 Help Now