Click to See Complete Forum and Search --> : Forms and dual action submit button


Jittor
12-05-2005, 04:59 PM
Hi Everyone,

I have created a basic form in DW. I would like the submit button to preform 2 actions. First email the info provided in the fields and second rediret to another page or possibly a PDF file for them to download. I am not sure exactly how to do this so any advice would be helpful. Will post code if needed. Thanks!

soccermatrix
12-07-2005, 11:24 AM
Here is one way I was able to do test it.

<form action="mailto:someEmail@emailprov.com" method="post" enctype="text/plain" name="form1" id="form1">
<input type="button" name="Button" value="Button" onclick="javascript:window.location.href('http://www.yahoo.com'); document.form1.submit();" />
</form>

Now keep in mind that the user will be notified of the email being sent. Since you are not using CGI to process the mail form, then the user's client email has to send the actual form.

The trouble with using this method to send form results is that it is highly dependent on the browser in use and the email client in use. In particular, some of the most popular versions of Internet Explorer will not work correctly. With all of the browser troubles, you're likely to lose about half of your readers' messages.

web beginner
05-14-2007, 10:48 AM
Hi, this has helped me also. Please can I ask how I use CGI to process the action? I am a good learner but I dont even know what CGI is? I am using dreamweaver in design mode but I am confident in editing html code. Please may I ask for advise from anyone?

spiresgate
03-03-2009, 07:09 AM
I was just searching for a solution to the problem 'two actions from one form' and I came across this which seems to be a way to do it.

Most of my hits on the web seemed to say it couldn't be done.

Thank you, SoccerMatrix, even though as an Englishman I have vowed never to let the word soccer pass my lips.

spiresgate
03-03-2009, 10:29 AM
But unfortunately it doesn't seem to work with Firefox, Opera, Safari, or Google Chrome.

I am trying to avoid server-side scripting. Can anyone suggest why it only works in IE?

Fang
03-03-2009, 11:06 AM
onclick="window.location.href='http://www.yahoo.com'; document.form1.submit();"

@web beginner cgi is Perl, any server side language can be used, PHP being very popular.
http://www.yourhtmlsource.com/cgi/

spiresgate
03-03-2009, 12:21 PM
Thank you Fang.

What I am trying to do is email the contents of a form (via action) and open an acknowledgement page.

Your sugestion worked just fine with IE. However with Safari it opens an email with the addresses in place but nothing in the body. With Opera nothing happpens at all when I click on the button. Any further enlightenment?

Fang
03-03-2009, 01:38 PM
This works in all browsers except Opera where only the email client is initiated, but no page redirect.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">
function mailIt() {
var elms=document.forms[0].elements;
var q='Dear '+elms.name.value+'%0AYour '+elms.comment.value+' in bla bla ...';
window.location.href='http://www.yahoo.com';
document.forms[0].action='mailto:name@domain.com?cc='+elms.email.value+'&subject=Feedback form&body=' + q;
document.forms[0].submit();
}
</script>

<style type="text/css">
label {display:block;}
</style>

</head>
<body>
<form action="#" method="post" onsubmit="mailIt(); return false;">
<div>
<label>Your name: <input type="text" name="name"></label>
<label>Your email: <input type="text" name="email"></label>
<label>Your comment: <textarea name="comment"></textarea></label>
<button type="submit">submit</button>
</form>
</body>
</html>
The only safe method is using a server side script. There are many sites that do this for 'free': http://www.bravenet.com/webtools/emailfwd/

spiresgate
03-04-2009, 02:01 AM
Thanks very much again.
I will implement your latest code for now (for education) and investigate the free server-side option for the longer term.