Sams Teach Yourself HTML, CSS & JavaScript Web Publishing in One Hour a Day

(singke) #1
ptg16476052

Creating Form Controls with the <input> Tag 339

12


The File Upload Control


The file control enables a user to upload a file when he submits the form. As you can see
in the following code, the type for the input element is set to file:


Input ▼



Figure 12.16 shows a file upload control.


Output ▼


If you want to use a file upload field on your form, you have to do a lot of behind-the-
scenes work to get everything working. For one thing, the program specified in the
action attribute of your form must be able to accept the file being uploaded. Second, you
have to use the post method for the form. Third, you must set the enctype attribute of
the

tag to multipart/form-data. Ordinarily, the default behavior is fine, but you
must change the enctype in this particular case.


FIGURE 12.16
The file upload
control.


It’s important to understand that when it comes to hidden form
fields, hidden means “won’t clutter up the page” rather than
“won’t be discoverable by the user.” Anyone can use the View
Source feature in the browser to look at the values in hidden form
fields, and if you use the GET method, those values will appear
in the URL when the form is submitted, too. Don’t think of hid-
den fields as a security feature but rather as a convenient way to
embed extra data in the form that you know the script that pro-
cesses the form input will need to use.

CAUTION
Free download pdf