Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modal Window Woes

Status
Not open for further replies.

Nutthick

MIS
Jan 14, 2004
126
GB
I'm struggling on this one. I have a modal window allowing the user to select a file top upload. When they click OK the file is uploaded, but I then need the modal window to close automatically, returning them back to the parent page. Is there a way to get perl to do this? I've tried putting an onClick event on the button, but it closes the parent window, not the modal.

Anyone got any ideas how to do it?

Thanks
 
Yep, a modal popup, so focus is on the popup until it is closed.
 
The upload script is as follows;

Code:
#!/usr/bin/perl -w

use CGI;

$upload_dir = "/home/tracks";

$query = new CGI;

$filename = $query->param("mytrack");
$track_name = $query->param("name");

# Strip off everything that includes backslashes
$filename =~ s/.*[\/\\](.*)/$1/;

# Get the file handle
$upload_filehandle = $query->upload("mytrack");

# Upload the file, use upload filename as our filename
open UPLOADFILE, ">$upload_dir/$filename";

binmode UPLOADFILE;

while ( <$upload_filehandle> )
{
	print UPLOADFILE $_;
}

close UPLOADFILE;

# Now need to close the window and dump back to parent

Thanks
 
O.K. The way this works is within the window.open() you must reference this script like below.
Code:
window.open('script.pl?action=form','win');

Here's the upload script.
Code:
#!/usr/bin/perl -w

use strict;

use CGI;
my $q = new CGI;

# configure
my $file_dir = "/home/tracks";

# do the action
my $action = $q->param('action');
my $method = {
    form   => \&form,
    upload => \&upload,
};
if ( $method->{$action} ) { $method->{$action}->(); } else { &form; }

# view the form
sub form {
    my ($done) = @_;

    my $close = $done == 1 ? "onLoad='self.close()'" : "";

    print <<FORM;
<html>
<body $close>

<!-- html form begin -->

<form method="POST" action="index.cgi" enctype="multipart/form-data">
<input type="hidden" name="action" value="upload">

<input type="text" name="name" size="28"><br>
<input type="file" name="file" size="28"><br>

<input type="submit">
</form>

<!-- html form end -->

</body>
</html>
FORM

}

# upload the file
sub upload {
    my $file = $q->upload('file');
    my $name = $q->param('name');

    $name =~ s/.*[\/\\](.*)/$1/;

    open( OUTFILE, ">$file_dir/$name" ) || die $!;
    binmode OUTFILE;
    for my $line (<$file>) {
        print OUTFILE $line;
    }
    close OUTFILE;

    form(1);  # reload the form closing the window
}

M. Brooks
 
Thanks for that. I've been on this for 16 hours now and I'm beat. I'll look at it tomorrow and let you know how I get on.
 
With Win32,
Code:
Return -1;
issued from the modal will return to the parent.
 
Thanks for the replies.

@mbrooks

I got your code working, it's taught me a few new tricks, and it works nicely, just it's not modal. I changed it slightly to make the window modal, but then when the 'close' command is called IE was popping up a new window just so it could close it. Very strange. Still I've taken a couple of ideas from your solution and mixed it in with something else, and some sleep, and I'm nearly there. Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top