Emailing Forms


There's another way to handle form data if you don't want to do any CGI programming; and because many readers of this book don't, I'll take a look at this other technique here. You can have the data in a form emailed to you if you set the ACTION attribute to a mailto: URL.

Here's an example. In this case, I'll email a form's data to steve@starpowder.com (a fictitious email address). Note also that I set the ENCTYPE attributethe MIME encoding of the form's datato "text/plain" :

(Listing 12-07.html on the web site)
 <HTML>      <HEAD>          <TITLE>CGI Example</TITLE>          <SCRIPT LANGUAGE="JavaScript">              <!--             function checkData()              {                  if(document.forms[0].text1.value == ""){                      window.alert("Please enter your name.")                      return false                  } else {                      return true                  }              }              // -->          </SCRIPT>      </HEAD>      <BODY>  <FORM ID="form1" METHOD="POST"   ACTION="mailto:steve@starpowder.com?subject=Web%20page%20email"   ENCTYPE="text/plain"">  Please enter your name:              <INPUT TYPE="TEXT" NAME="text">              <BR>              <INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Submit">              <INPUT TYPE="RESET">          </FORM>      </BODY>  </HTML> 

Here's the body of the email that arrives, in plain text because I set the ENCTYPE attribute to "text/plain" :

 text=Hello  Submit=Submit 

That's how the data will arrive in the emailas name =value , where name is the name of the control and value is the data in the control.

Tip

The submit method does not work with mailto: URLs for security reasons (so a JavaScript programmer can't get your email address unless you okay it).


Sending form data back to a program on the server is fine; of course you don't need to send a form's data back to the server at all, you can create your entire program in JavaScript and run it all in the browser as we're doing throughout this book.



Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net