|
You don't need a Crystal Ball |
![]() |
|
to Search for Files |
| SearchWin Home |
| Article Home |
| Web Forms |
| Borderless Windows |
| Cookies-Part One |
| Cookies-Part Two |
| About Span and Div. |
| Using CSS-Part 1 |
| Using CSS-Part 2 |
| Using CSS-Part 3 |
| About DOCTYPE |
| Tables With XML |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
Getting Form Data From A Web Page Without Server Intervention There are many potential uses for collecting data from web pages: site & product feedback, information about visitors, product interest requests & site visitor registration to name just a few. Most of the time, the data collection is handled by Server side scripts. Traditionally, CGI & PERL are commonly used to get the information from a web page & then initiate the processing of it. More recently, Active Server Pages are playing an important role in data collection. What if you do not have access to setting up server scripts either because the ISP doesn't allow it or because they have only a limited number of 'pre-approved' scripts for customers to use. Is there any other way of getting data from a web Form to you? This article discusses one Client Side technique for getting Form data without Server intervention. Email is a very simple way to send Form data. Like all simple things, it does have drawbacks. Pros: It makes a basic web page form a breeze to do & you get the Users default email address (assuming they have a real address set up in their mail program). Cons: It's unsecured; should not be used for any confidential information, e.g., CC #'s and the like. It's also a bit of work at the recipient end. The data is sent in the body of the email or as an attachment, so you need to go through the email/attachments (either manually or with a script/program), parse them for the data and then save it to a Database/File. But for low quantity, non-secure data emailing Form data can be useful. The techniques discussed, work (for sure) with Internet Explorer and Netscape V4.x+ (I think back to NS V2.x and IE V3.x).
How to Email Form Data The HTML Tag "FORM" accepts main three parameters -
ACTION, METHOD, and ENCTYPE. The destination URL of the data contained in the
form is specified in the ACTION parameter. Setting the value of ACTION to an
email URL e.g., mailto:my_email@server.com and the METHOD to "POST" will send
the contents of the form to the specified email address as an attachment. The
attachment will contain a string that is a list of field name and values
separated by the "&" character. Improving on the Basic Form If your web server supports it, adding ENCTYPE to the Form Tag parameters specifies the mime type used to encode the form data. Setting ENCTYPE="text/plain" can get rid of the attachment and place the data directly in the body of the email. This can simplify the processing a bit. Other mime types are possible depending on your server & email program. Enhancing the Form with JavaScript The basic form leaves a lot to be desired. There's nothing to validate the data in the fields nor prevent the fields from being blank. We can use a small script to address these deficiencies. Both NS and IE respond to the basic HTML events. Form events include onclick & onSubmit (and others). Adding a script call to the Form's onSubmit event can check that the fields aren't blank before allowing the Form to be sent. If the script returns a True the Form data is emailed, otherwise nothing happens. We could add a few other goodies here too. For example, collect some additional info about the User or change the emails subject to reflect the location & page the form originated from. For the additional data, add hidden fields to the form and then fill in their value in the onSubmit script. One of the FORM's standard input elements is RESET, a
button element. By adding a script to it's onclick event, a mechanism to clear
the form can be provided. Getting More Sophisticated The examples I've talked about so far are ok for a simple
Form. What about fields requiring numbers only? Or a certain format such as
phone numbers or zip codes or dates? With Server side scripts (CGI, PERL, etc.)
the validation & formatting is done by the Server. We can accomplish similar
validation with Client side scripting too. Fortunately, a lot of that work has
been done for us. Netscape has kindly made available
for public use a script called FormChek.js (see Netscape link at page
bottom) A FORM Field's onblur event (occurs when the User leaves that field, i.e., focus is changed to something else) can be used to call a script to validate or format that fields value. In Conclusion Regardless of how much we pretty up the html forms, client side scripts pretty much are limited to emailing the data and are subject to the limitations I mentioned at the start. One work around is to build a Java applet that connects to a database. This could allow a page to directly write data to some database. That's a topic in itself. Another approach that is more flexible than CGI & PERL, are servers with FrontPage extensions or LiveWire. They have built-in form validation and data connection capability. All client side solutions are at least somewhat problematic with respect to security. There are also some "script servers" around - servers that external pages to use their CGI scripts. Some are 'Freebie' for basic stuff and others that provide custom scripts or processing service for fee. I've worked up three examples showing the things I've talked about. The first, is a page using only HTML Tags. The second, adds JavaScript to provide some simple field validation, and the third enhances the HTML by placing the Form in a Table and takes a step toward generalizing the JavaScripts. Download ALL the samples & FormChek.js at http://www.dalesplace.net/Form_Mail4.zip More information about Forms & JavaScript:
|