Solved

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

Posted on 2004-09-14
8
310 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
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

 

Author Comment

by:tjintro
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, i was on holiday for a while :-)

Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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

17 Experts available now in Live!

Get 1:1 Help Now