PDA

View Full Version : form evaluation and action


allyson
11-07-2002, 05:38 AM
Hi

Take a look at http://homepages.ihug.co.nz/~usateden/panacea/organisation/enrolment2.htm . The javascript code makes sure that the form is filled in accurately, and when the user clicks 'Send' the alert box comes up, saying that the information has been sent, but the form does not go to the stated email address. I think that I haven't set up the action properly. How could I modify the script, so that action is set up properly? Please help. Thank-you.


<form name="TheForm">
<p><input type="text" name="nm" size="30">Name <br>
<input type="text" name="age" size="5">Age <br>
<input type="text" name="add" size="40">Address <br>
<input type="text" name="city" size="40">City<br>
<br>
<input type="text" name="disability" size="40">Disability<br>
<br>
<input type="text" name="em" size="33"> E-mail address <br>
<input type="text" name="emx" size="33"> Re-enter to confirm </p>
<div align="center"><center><p>&nbsp;</p>
</center></div><div align="center"><center><p><input type="button" value="Submit"
name="SB" onClick="sendOff();"><input type="reset" name="B2" value="Reset"> <script
language="JavaScript1.2">

// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this header

var good;
function checkEmailAddress(field) {

// Note: The next expression must be all on one line...
// allow no spaces, linefeeds, or carriage returns!
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

if (goodEmail){
good = true
} else {
alert('Please enter a valid e-mail address.')
field.focus()
field.select()
good = false
}
}

function sendOff(){
nmcheck = document.TheForm.nm.value
adcheck = document.TheForm.add.value
agecheck=document.TheForm.age.value
discheck=document.TheForm.disability.value

if (nmcheck.length <1) {
alert('Please enter your name.')
return
}
if (adcheck.length<1) {
alert('Please enter your address.')
return
}
if (agecheck.length<2) {
alert('Please enter your age.')
return
}


good = false
checkEmailAddress(document.TheForm.em)
if ((document.TheForm.em.value ==
document.TheForm.emx.value)&&(good)){
// This is where you put your action
// if name and email addresses are good.
// We show an alert box, here; but you can
// use a window.location= 'http://address'
// to call a subsequent html page,
// or a Perl script, etc.
alert("Information is being sent to Panacea Arts")

METHOD = POST
ENCTYPE = "text/plain"
ACTION = "mailto:allyson@paradise.net.nz?subject=Comments from home"

}
if ((document.TheForm.em.value !=
document.TheForm.emx.value)&&(good)){
alert('Both e-mail address entries must match.')
}
}
</script> </p>
</center></div></font>
</form>
</body>
</html>

glenngv
11-07-2002, 05:58 AM
changes these lines:

METHOD = POST
ENCTYPE = "text/plain"
ACTION = "mailto:allyson@paradise.net.nz?subject=Comments from home"

to:

document.TheForm.method = "post";
document.TheForm.encoding = "text/plain";
document.TheForm.action = "mailto:allyson@paradise.net.nz?subject=Comments from home"

you may want to save document.TheForm in a variable to optimize your code

...or just simply:

<form name="TheForm" method="post" enctype="text/plain" action="mailto:allyson@paradise.net.nz?subject=Comments from home">

but, will the form data be sent to the mail client since you just use mailto: in your form action?
I think you need to use a server-side language to send form data via email.

dsdemmin
11-07-2002, 06:59 AM
A mailto script will work with Netscape but the user will get a 'permission' window allowing the email.

IE < 3.0 will not allow form emailing. Newer IE's will but again with a warning window.

If you have access to cgi scripting, I would use Matt's FormMail (http://www.scriptarchive.com/formmail.html) ... easy to setup and it works with a simple form action on your page like this:

<form action="http://www.YourURL.com/cgi-bin/FormMail.cgi" method="POST" name="form1">
<input type="hidden" name="recipient" value="you@Here.com,you@HereToo.com">
<input type="hidden" name="subject" value="This appears in the Subject line of the Email">
<input type="hidden" name="redirect" value="http://www.YourURL.com/SomeOtherPage.htm">

Good luck.

allyson
11-08-2002, 02:39 AM
Hi

Thank-you for your suggestions. Unfortunately they don't work. I used:

document.TheForm.method = "post";
document.TheForm.encoding = "text/plain";
document.TheForm.action = "mailto:allyson@paradise.net.nz?subject=Comments from home";

I know form processing usually works, but this is particularly difficult, for some reason. Has anyone got some more suggestions on how I can make it work, please?

bye
Allyson

glenngv
11-08-2002, 03:49 AM
what specifically does not work? I told you in the last part of my post that you need a server-side language like ASP, PHP, etc to send user-filled data to an email address.

whammy
11-08-2002, 03:54 AM
Yeah, emailing with javascript just doesn't do what you want - and won't work in all browsers.

You can use my free formmail script if you want, just sign up for my website, it's free...

... or use a CGI formmail program like Matt's - but be aware there are some hacks for that script that hackers can exploit to use it as a spam program unless you set it up right and research it a bit.

I ran into the same problems as you, and that's one of the things that prompted me to learn ASP a while back - you might want to consider the same things, since if you want to store user data, etc. you'll have to use server-side. :D

It's really a lot of fun, and not as hard as you might think. :)