Page 147 - DCAP202_Fundamentals of Web Programming
P. 147
Fundamentals of Web Programming
Notes Introduction
A form is exactly what it says it is, a form that the user fills-in. It can have a variety of different
types of input fields that you specify when you design the form (e.g. name, address, age, etc.) and
the user fills-in prior to submitting the form. The only problem with HTML forms is that they
are not much use by themselves because a traditional HTML form will only work in conjunction
with a specially written server-side CGI program or script.
12.1 Properties and Methods
The method attribute tells the server how to submit the form information. There are two methods,
get and post. The default method is get.
method=”get”
This sends the form information by including it on the URL. The get method sends the information
to the server in one step. It is best used for forms where the information is not secure (as it can
be seen in the URL), and the amount of information passed is small. Get requests are useful if
you want to call a CGI from a link.
<form method=”get” action=””>
When to use the get method:
Short forms, with only 1 or 2 input fields
Forms with primarily select, radio, and checkbox fields
When the form needs to be called from a link
For mailto forms
method=”post”
This sends the form information in the HTTP environment. It is a little more secure, as your
customers can’t see it directly (although it is sent in clear text, so it can be hijacked by hackers
with packet sniffers).
Notes The post method sends the data to the server in two steps. First the browser contacts
the server and after the contact is made, it sends the information.
It is best used when you have a lot of information to pass (either textarea tags, or just a lot of
fields.)
<form method=”post” action=””>
When to use the post method:
Longer forms, more than 3 input fields
Forms with large textarea fields
Forms where security is more important (but if security is important, you should use a
secure server too)
Task Compare and contrast get method and post method.
140 LOVELY PROFESSIONAL UNIVERSITY