ptg16476052
322 LESSON 12: Designing Forms
The general rule when it comes to choosing between post and get is that if the form will
change any data on the server, you should use post. If the form is used to retrieve infor-
mation, using get is fine. For example, suppose that you’re writing a message board pro-
gram. The registration form for new users and the form used to publish messages should
use the post method. If you have a form that enables the user to show all the posts
entered on a certain date, it could use the get method.
HTML5 and modern browsers now offer a validation feature before the form is submit-
ted. The browsers use a combination of rules written in the control attributes and the
attribute types themselves to determine whether the content is what you’re asking for.
You’ll learn about this in more detail later in this lesson. But because of this feature, the
form tag has an attribute novalidate that lets you turn off validation on your forms. The
main reason you will use this attribute is to test the JavaScript and server-side validation
mechanisms you have in place. This is a Boolean attribute, so you don’t need to include
any values. Simply add it to your form tag:
<form novalidate>
Another new attribute of the <form> tag is the autocomplete attribute. It can have the
value of on or off. on is the default, and it tells the browser to attempt to predict the
value when a user is typing in a form control. By turning the autocomplete attribute off
you tell the browser to avoid suggesting values for form fields. You can turn autocomple-
tion on or off for your entire form by adding it to your <form> tag:
<form autocomplete="off">
Two other less-often used attributes of the <form> tag are enctype and accept-charset.
enctype defines how form data is encoded when it’s sent to the server, and accept-charset
defines the character encodings to be used for the form submission. The default for enctype
is application/x-www-form-urlencoded, and the default for accept-charset is the same
DO use the POST method when data
on the server will be changed in any
way.
DO use the GET method if the form
just requests data (like search forms,
for example).
DO use the GET method if you want to
bookmark the results of the form sub-
mission.
DON’T use the GET method if you do
not want the form parameters to be
visible in a URL.
DON’T use the GET method if the form
is used to delete information.
DO DON’T
▼
▼