Link to home
Start Free TrialLog in
Avatar of tjintro
tjintro

asked on

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>
Avatar of tomaugerdotcom
tomaugerdotcom
Flag of Canada image

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.
Avatar of tjintro
tjintro

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of tomaugerdotcom
tomaugerdotcom
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tjintro

ASKER

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
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 :)
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
Avatar of tjintro

ASKER

Sorry, i was on holiday for a while :-)

Thanks