Chapter 6. Forms
6.1. The <form> Tag
You place a form anywhere inside the body of an HTML document with its elements enclosed by the <form> tag and its respective end tag </form>. All of the form elements within a <form> tag comprise a single form. The browser sends all of the values of these elements—blank, default, or user-modified—when the user submits the form to the server.
<form action="http://www.oreilly.com/cgi-bin/update" > ... </form>
The example URL tells the browser to contact the server named www.oreilly.com and pass along the user's form values to the application named update, located in the cgi-bin directory.
The browser specially encodes the form's data before it passes the data to the server so it doesn't become scrambled or corrupted during the transmission. It's up to the server to decode the parameters or pass them, still encoded, to the application.
The standard encoding format is the media type named application/x-www-form-urlencoded. You can change that encoding with the optional enctype attribute in the <form> tag. If you do elect to use an alternative encoding, the only other supported format is multipart/form-data.
The standard encoding—application/x-www-form-urlencoded—converts any spaces in the form values to a plus sign (+), nonalphanumeric characters into a percent sign (%) followed by two hexadecimal digits that are the ASCII code of the character, and the line breaks in multiline form data into %0D%0A. (See Chapter 12 for more information on URL encoding.)
The multipart/form-data encoding encapsulates the fields in the form as several parts of a single MIME-compatible compound document.
The other required attribute for the <form> tag sets the method by which the browser sends the form's data to the server for processing. There are two ways: the POST method and the GET method. See Chapter 12 for more information on GET and POST.
Copyright © 2003 O'Reilly & Associates. All rights reserved.