• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

send email and download exe-file on submit form at same time

Hey

i'm trying to download an exe-file and send an email at the same time to the server on a form submit.
The javascript works when I take the code out the form. When it's in the form it only runs the form-script. (cgi).
Have anyone an idea?

Thanks a lot !!

-------------------------------------------------------------------------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<script language="javascript">
function processDownload()
  {
     window.location.href = "http://www.boekje.exe";
  }
</script>
</head>
<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor="#ffffff">
<table border="0" cellspacing="0" cellpadding="7" width="250" align="center">
<tr><td height="80" align="center"><p>
<form method="GET" enctype="multipart/form-data" action="http://www.boekje.com/boekje.xar?">
<input name="ACTION" type="hidden" value="provide-email"/>
          <table border="0" cellspacing="0" cellpadding="0">
          <tr><td width="50"></td><td></td></tr>
          <tr><td width="50">email:</td><td><input name="EMAIL" type="text"/></td></tr>
          <tr><td width="50"></td>
          <td><input name="submit" type="image" src="images/zend.gif"  onClick="javascript:processDownload();" /></td></tr>
  </table>
  </form></p></td>
</table>
</body>
</html>
0
tjintro
Asked:
tjintro
  • 3
  • 3
1 Solution
 
tomaugerdotcomCommented:
Hmm. It looks like the window.location() call and the form submit are colliding with each other (ie: one is happening before the other and cancelling the other.)

A couple of things to try:

1. get rid of the <input type="submit"> and replace with an <input type="button"> but keep the onClick="processDownload();" function. Add a "name" tag to the form so your javaScript function can access the form in order to submit it. Something like <form name="myForm" action="...etc..."> Now, edit the processDownload() function to look like this:

function processDownload()
  {
    document.myForm.submit();
     window.location.href = "http://www.boekje.exe";
  }


2. if that doesn't work, it may still be colliding, so wait a moment before changing the location of the window:

function processDownload()
  {
    document.myForm.submit();
     setTimeout('window.location.href = "http://www.boekje.exe"', 1000); // wait 1 sec before changing location
  }

3. finally, if that doesn't work, why not have the response from the cgi-script that processes your download go to another window?

<form name="myForm" method="GET" enctype="multipart/form-data" action="http://www.boekje.com/boekje.xar?" target="cgiWindow">

Hope this helps
Tom Auger

One last note: if I were writing this script from scratch, I would have the script that processes the upload also generate and send the email. That way, one process would be dependent on the other. In other words, if the upload fails for some reason, the email would not get sent, or it would be an "error" email that gets sent or something like that. The way you have it now, the two processes are disconnected.

Goede dag.
0
 
tjintroAuthor Commented:
hey tom, thanks for the answer,

good idea's, i've tried all the things, but it doesn't work yet.

i get the response: "emailrecieved:tom@boekje.com" but don't get the pop-up for downloading the exe-file.

Have you got any idea why it doens't download after the changes? When I read your comment i thought it would be solved. :-)

Thanks en goeie dag terug :-)
Tom
0
 
tomaugerdotcomCommented:
OK, sorry - in re-reading your email I realized I thought you were UPLOADING a file not downloading one. I recently wanted to do something like this - very much like C|Net or downloads.com does it. Well, I came up with a method but it uses iFrames, which means that it will probably only work in Explorer (not Netscape). For my purposes this was fine, but I hate recommending a browser-specific solution. Here's what I did:

Using the same strategy as above, instead of redirecting the user to  http://www.boekje.exe", send the user to an html file that looks something like this:

<html><head><title>Downloading File</title></head>
<body>
  <p>File is downloading. If it doesn't start right away, click <a href="http://www.boekje.exe">[here]</a><p>
  <iframe src="http://www.boekje.exe"></iframe>
</body></html>

The key is the iframe (which only works in IE). This should invoke the "File Save" dialog box which allows you to save your file or open it directly.

Tom, I noticed something weird though: the URL ="http://www.boekje.exe" looks weird. did you just invent that for this example or is it supposed to point to a real file? Maybe that's where the problem has been all along?

groeten
Tom Auger

0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
tjintroAuthor Commented:
Hey tom

Thanks, the iframe works very well. I send the email to the cgi and give an html page with iframe back.
More then 96% visitors use Explorer on the site.

Thanks a lot Tom

groetjes
0
 
fantasydreamingCommented:
The preferred way to do this would be to have the email-sending form return a redirect header in the form of:
Location: http://my.site.com/my_file.exe\n\n

Then, after the email is sent, it would immediately begin sending the file.  

Its the more 'hardcore' way to do it, but it does require modifying the perl script.  And it sounds like you already got a solution, but just thought I'd throw it out there :)
0
 
tomaugerdotcomCommented:
Actually, the REALLY hardcore way of doing it is having your form actually send the appropriate Mime-type for the file, read the file in binmode and then send it directly out to the client. However, as fantasydreaming mentioned, this is seriously hardcore and would require

a. recognizing the file extension and then sending the appropriate mime-type
b. reading in the file with binmode on
c. sending it to the client

so some heavy mods to the script. You would want to do this only in circumstrances when you don't want the end-user to be able to see where the original file resides (to "force" them to use your script to download it for example.) For an example of this, check out http://www.nrx.com/whitepapers

Cheers

Tom
0
 
tjintroAuthor Commented:
Sorry, i was on holiday for a while :-)

Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now