|
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
01) WHAT IS A FORM?A form is simply a Web page that can obtain information from the user via text boxes, drop-down lists, and command buttons. A good example (and probably one of the most popular) is that of a "guest book" that allows people to "sign" it when they visit a Web page. Forms are used for many things, including: Gathering user information and getting a person's user name and/or password for verification. 02) GETTING STARTED CREATING FORMSIt's very easy to set up a form. The problem usually occurs when you try to obtain access to the information that the user has input into your form. Why? Because the information is stored and requires some programming, such as CGI. But, I'm jumping ahead of myself. CGI discussion comes a little in this chapter. The tags for a form are <FORM> and </FORM>. These can go anywhere inside of the body of the Web page. All of the other form-related tags (which I'll discuss further down) go between the <FORM> and </FORM> tags. Here's the generic format for forms:
<FORM ACTION="URL" METHOD=METHOD> In the above format, the ACTION attribute tells the browser where to go to send the form's data. This will almost always be a program (also called a script) that processes the data and then does the action. The URL, of course, is the address of the Web page that holds the program that holds the form's data. Sounds confusing, doesn't it?
The METHOD attribute tells the browser *how* to send the form's data to the address (URL) specified with the ACTION. There are two (2) choices for the METHOD: POST and GET. The POST method is the most reliable, as the GET METHOD sometimes causes errors in large forms. Here's a sample of the form code:
<FORM ACTION="http://www.rivermoo.com/tidbits/html/form" METHOD=POST>
Once a user has input all of his/her information, then s/he's ready for it to be sent to the program specified by the <FORM> tag's ACTION attribute. A submit button is like an "OK" button. It says, "Ok, I'm finished inputting information into this form. It's ready to go to you." So, what's the format for the submit button? <INPUT TYPE=SUBMIT>
What if you don't want it to say 'Submit' or 'Send' or whatever the browser is using? What if you have your own special "label" that you'd like to call it? Then, simply add another attribute to the <INPUT> tag called VALUE and set VALUE to equal whatever word or phrase you want it to say. <INPUT TYPE=SUBMIT VALUE="I'm done! Take my information!"> Now, let's see the basic HTML code for a very simple form... using the examples above.
<HTML> It's one thing to see the code; it's another to see the actual Web page that code will generate.
04) THE RESET BUTTON: STARTING OVERWhat is the reset button for? It's for all the users who will make a mistake somewhere when he/she is typing the information into the form. It's for the person that gets all the way to the end and glances back up and notices a typo at the top of the form! It's a way to start over. So, what does a reset button actually do? It clears all the data from the form and allows you to start over. Here's the reset button tag: <INPUT TYPE=RESET> This tag creates a button called 'RESET'. Again, if you wish, you can customize your button to say whatever you want it to say by adding a VALUE attribute. How about something like this? <INPUT TYPE=RESET VALUE="Uh Oh, Let Me Start Over!">
Sometimes, all the information you want from a user is something simple. Like his/her name. When that's the case (where you only need a single line of text input), you should use a simple text box. <INPUT TYPE=TEXT NAME="Whatever You Want This Field Named"> In the above code, you might want the user to enter his/her last name, in which you would simply put something like "Last Name" for the NAME tag. <INPUT TYPE=TEXT NAME="Last Name"> Since users can't read your mind and *know* that you want their last name in that box, you should put something in front of it to indicate what type of information you're wanting entered into the text box. The code for specifying the type of information you want would appear similar to: Last Name: <INPUT TYPE=TEXT NAME="Last Name"> Below is some HTML code for using text boxes to gather some data from the user.
<HTML> Now, I bet you'd like to see the above form in action.
You know, it'd be too easy if that's all a text box did. There are three (3) perks to using text boxes that you should know about.
06) USING TEXT BOXES FOR MULTIPLE LINESSometimes, one line of text just isn't enough; for instance, an address. You would probably want at least two (2) lines for the address. Or maybe you just want to provide users a place to comment. In both of these instances, you're better off using a TEXT AREA, rather than a text box. A TEXT AREA is a rectangle that allows users to input text, but it isn't limited to just a single line.
<TEXTAREA NAME="FIELD NAME" ROWS=TotalRowsYouWant COLS=TotalColumnsYouWant WRAP> In the above format, FIELD NAME is the name of whatever input you're gathering, TotalRowsYouWant is the total number of lines you wish to have displayed, TotalColumnsYouWant is the total number of columns you wish to have displayed, and WRAP tells the user's browser to wrap the text around to the next line if it reaches the end of a row (this might not be supported by all browsers). Below is the code for showing how to use a text area tag.
<HTML> Phew. Did you understand all of that? Would it help if you could see what that looks like in action? I thought so. ;)
07) TOGGLING CHECK BOXESCheck boxes are nifty little form boxes that you can use when you want to simply have users select true/false, yes/no, or whatever. Check boxes are used when there are only two (2) answers possible. Here's the format for check boxes: <INPUT TYPE=CHECKBOX NAME="Field Name"> Again, FIELD NAME is the name of whatever it is that you're asking input on at this time. What if you want to show a list of items, and have them all already checked by default? Add the attribute of CHECKED to your <INPUT> tag. <INPUT TYPE=CHECKBOX NAME="Hobbies" CHECKED> Did you notice that I named the above input checkbox Hobbies? What would be the code for this? <HTML> Wow, that sure looked like a lot of typing. It wasn't, though. I just love the cut and paste options. Oh, I bet you'd love to see what the check box Web page looks like, too.
08) RADIO BUTTONSThe difference between check boxes and radio buttons is this: Check boxes allow for one (1) of two (2) options and radio buttons allow for more than two (2) options, but just one (1) answer. For instance. A true/false question on a test would best be displayed with a check box, but a multiple choice question with four (4) possible answers would best be done with radio buttons.
Here's the format for using radio buttons:
<INPUT TYPE=RADIO NAME="Field Name" VALUE="Value"> You should know by now that the Field Name is the specific name you've given to this particular input box.
VALUE is a unique string of text that specifies the value of the option when it's selected. You can also add CHECKED in the tag to one of the buttons in a group to have the browser select that one by default. Ready for some more code?
<HTML> When you view the Web page from the above code, be sure to notice that I have an answer already checked by default. First, what are selection lists? I'm sure you've probably seen them, if you've been surfing the Web very long. They're sometimes drop-down boxes and they can look like this. There are a couple of tags involved in a selection list. First, are the <SELECT> and </SELECT> tags. This is the tag that allows you to have a larger selection box. There are two (2) attributes in a <SELECT> tag. First is the all-too-familiar Field Name and second is a SIZE attribute. The SIZE attribute sets the selection list to a specific number of items to be displayed. If you omit the SIZE attribute, like I did in the above sample Web page, it becomes a drop-down box. If you include a SIZE attribute, it's simply a large selection box. For what it's worth, I prefer the drop-down look. Here's the format for the <SELECT> tag: <SELECT NAME="Field Name" SIZE=NumberOfItems> Here's the source code for the first selection list you viewed above.
<HTML> The <OPTION> and </OPTION> tags are used to give your choices. Isn't this getting easier to understand? :)
10) CGI WHAT?What is CGI? First, CGI is an acronym for Common Gateway Interface. CGI is a method of transferring form data in a manner that makes it fairly easy to incorporate into a program and then allow you to use it in all the ways that you need to. All of the form tags in this chapter allow you to create the forms, but you must have a way to get the information back from the computer it was stored on. That's the job of CGI; a program or script that allows you to get that information back. So, how do you find CGI programs? You have several options available to you.
Enjoy creating your own forms in the future! Good luck!
|