?
Solved

CGI problem (Help!!)

Posted on 2002-05-28
3
Medium Priority
?
190 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 400 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

Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

Question has a verified solution.

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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

777 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