HTML and CSS Reference
In-Depth Information
The action Attribute. The action attribute is assigned the URL of the server program
that will process the form data. After the user enters the information requested in the
form, he or she will normally click a Submit button. That button might say “Order now,”
“Send Your Order!” or simply “Submit.” When this button is clicked, the browser goes
to the value in the action attribute to see where to send the data, which is normally the
URL of a PHP, Perl CGI, or ASP script. The URL can be a relative or absolute URL (e.g.,
http://localhost/cgi-bin/validate.pl or simply cgi-bin/validate.pl or validate.php , etc.).
When the form data is sent to the server program, it is processed further, validated, sent
to a database or file, used in an e-mail, and so on.
Form data doesn't always get sent to a server program. It might be used by JavaScript
to pass information to functions, cookies, and so on. To prevent the form from directing
the page to a server, the action attribute can be assigned the empty string or simply be
omitted, in which case the form data will not be sent.
The method Attribute. A method attribute can be assigned to the <form> tag. The
method attribute indicates how the form data will be sent to the server. Simply put, for
pure queries, the GET method is normally used, and for submitting form data, the POST
method is used. (The method names are not case sensitive.)
The GET method is the default (does not need to be specified) and is used every time
the browser requests a document. The GET method is preferable for operations that will
not affect the state of the server; that is, simple document retrieval, queries, database
lookups, bookmarking, and the like. It is the only method used for retrieving static
HTML files and images. The GET method passes data to the server by appending the
data to the URL (called the query string). The query string, prepended with a question
mark, is a URL-encoded string consisting of name/value pairs. It can be seen in the Loca-
tion bar of the browser as soon as the user clicks the Submit button in a form. In Figure
11.5 the name/value pairs being sent to the server are color=yellow .
You can also view HTTP headers of a page while browsing with a Firefox add-on
called Live Headers ( http://livehttpheaders.mozdev.org/ ). See Figures 11.5 and 11.6.
The POST method is preferred for handling operations that might change the state of
the server, such as adding or deleting records from a database, uploading files, sending
e-mail, and so on. The POST method is the most commonly used alternative when send-
ing form data (see Figure 11.6). The post data is URL encoded in the same way it is with
the get method, but it is posted to the server as a message body, similar to an e-mail mes-
sage, rather than in a URL. The post method can be used when sending large amounts
of data and is not shown in the Location bar of the browser, although it can be viewed
as View Source under the browser's View option. If you try to backbutton post data, the
browser normally sends you a warning so that you do not destroy or lose a previous
transaction. This caution presumes that because the post method was used, there might
be some permanent change to the state of the server.
 
Search WWH ::




Custom Search