The Wayback Machine - https://web.archive.org/web/20090531043905/http://www.webreference.com:80/html/tutorial13/5.html


spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / html / tutorials / 13 / 5

index123456789101112131415161718192021exercises1

Tutorial 13: Giving Form to Forms

Developer News
Rails 3 Gets Supersized With Merb
SpringSource, Hyperic Merge for App Management
Get Ready for Windows 7 'Release Candidate'

Form submission

After the form data has been encoded, it is sent to a Web server to be processed. The location of the processing program is given by the ACTION attribute. The sending of the data is done in one of two ways, as specified by the METHOD attribute.

The first way to send a form is by using the GET method. This works similarly to the ISINDEX element: It encodes the data, takes the URL in the ACTION attribute, and stuffs a question mark and the encoded data at the end. So, imagine that our first form (with only first and last name fields) was specified using a FORM element like this:

<FORM
 ENCTYPE="application/x-www-form-urlencoded"
 METHOD="get"
 ACTION="http://www.acme.com/cgi-bin/name.cgi"
>

When the form is submitted, the browser will just try to load the following URL:

http://www.acme.com/cgi-bin/name.cgi?lastname=Piperoglou&firstname=Stephanos

When you use the GET method, you must use the application/x-www-form-urlencoded encoding type, to ensure that the encoded data can be used as part of a URL. This means that you can't send files with this method. This method also has various other disadvantages, mostly to do with security - it is difficult to encrypt the encoded form data while it is travelling to the server, and if this is your credit card number or some other piece of even more sensitive information like an embarassing photo, this could be very important. Also, many servers and/or browsers have a limit for how long a URL can be, meaning that you can't send more than a few name/value pairs this way. Which brings us to the POST method.

The POST method loads the URI in the ACTION attribute and sends the encoded data via the HTTP POST method, the technicalitites of which you don't have to worry about. Put simply, this is just like normally loading a URL, but some extra data is also sent along. You can use either encoding with the POST method, but remember that you must use multipart/form-data if you want to be able to send files.

The POST method also has another use. The URL in the ACTION attribute can be a mailto: URL, in which case the form data is encoded and mailed off to the address specified. This is nice if you want to create a quick form that just sends the results to you, but has several disadvantages: Firstly, the results will most probably be unencrypted. Secondly, the browser will not load a different URL after the form is submitted, so the user will not get any immediate response after submitting the form, not even to acknowledge that the data is submitted. Finally, you'll receive the encoded data, and you might not be too happy about deciphering the string to figure out what it means. So this method is bad - I don't use it, and I'm lazy. If you want results in the mail, there are hundreds of ready-made scripts that will process a form and send you the results in a more digestible format.

The default value of the ACTION attribute is the URL of the document that contains the form. The default submission method is GET, and the default encoding is application/x-www-form-urlencoded. However, it's best not to rely on these values and set them explicitly.

index123456789101112131415161718192021exercises1

Produced by Stephanos Piperoglou

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info
Copyright 2009 WebMediaBrands Inc. All Rights Reserved.

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Getting Started with URL Rewriting with Apache · Kicking the Tires on Your Next CMS · User Personalization with PHP: The Final Scripts
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Write SQL Code for MySQL Using HeidiSQL 4 · Government Mobility and Why It's Not an Oxymoron · Site Building with Photoshop and Dreamweaver

URL: http://www.webreference.com/html/tutorial13/5.html

Created: May 28, 1998
Revised: February 25, 1999

Morty Proxy This is a proxified and sanitized view of the page, visit original site.