Solved

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

Posted on 2004-09-14
8
312 Views
Last Modified: 2013-12-25
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
Comment
Question by:tjintro
  • 3
  • 3
8 Comments
 
LVL 14

Expert Comment

by:tomaugerdotcom
ID: 12054569
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
 

Author Comment

by:tjintro
ID: 12055086
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
 
LVL 14

Accepted Solution

by:
tomaugerdotcom earned 125 total points
ID: 12057545
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:tjintro
ID: 12061998
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
 

Expert Comment

by:fantasydreaming
ID: 12064842
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
 
LVL 14

Expert Comment

by:tomaugerdotcom
ID: 12065550
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
 

Author Comment

by:tjintro
ID: 12257189
Sorry, i was on holiday for a while :-)

Thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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…
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…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

803 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