Fill In The Blank....Everyone who uses the internet has encountered forms before, wether they are aware of it or not. Forms are a grouping of fields and buttons used to collect information (input from the user) that is applied to a script that in turn spits out a reply based upon what was typed by the user. This script is invisible to the user, but is the most important part; without the CGI (Common Gateway Interface) and SSI (Server Side Interface) scripts, all a form can do is look pretty. There are five basic types of input devices that can be used in a form, and all have their own unique uses and degrees of usefulness. Each of these is detailed in it's own subsection below. Basic Forms
The basic principles used in creating forms will always remain the same, no matter how large or small the complete
form is. A form will always start with <form action="http://www.yourserver.com/cgi-bin/script.pl" method="post">
Body of Form goes here.... </form>The Next Step....Just as there are certain attributes that all One final note: No value of any attribute in a form may contain spaces; unless it is in quotation marks. If you need to use a space, and don't want to place values in quotes, replace it with and underscore.
value=i_need_a_space or value="i need a space"). | |
The Text BoxThe first type of field, and the most commonly used, is the text box. This is
most frequently used as a place to enter one's username, password, age, or other short answer-type
information. The HTML tags to create an input text box are Several attributes can (and should) be applied to this tag. The first of these is "size="; as the name implies,
this attribute sets the visible size of the text box. The value for this attribute is a number of characters. The second attribute
is "maxlength" and again the name is pretty self explanatory. The user can type as much as they wish, but anything beyond
the maximum length for the field will not appear. Let us suppose you are asking for the user's year of birth.
For this purpose, you need a relatively short text box,and the maximum number of characters should be four. Thus, the following HTML: <input name=birth_year size=4 maxlength=4>Generates this text box: The Text Area FieldThis is the only other type of text field availible, and it is most often used when a lengthy respose is required. The most common use
of this type of field is entering a descriptive paragraph or other message. The HTML tags are The size of the field is set using two attributes "rows=" sets the height (number of lines of text), and "cols=" sets the width
(a number of characters). Based on those two attributes, the following HTML: <textarea name=description cols=30 rows=6>What's your beef?</textarea>Generates this text field: Radio ButtonsRadio buttons are most commonly used in places where a simple yes or no answer will suffice, or for other similar occasions
when there is a small number of possible answers to the particular question. These buttons also often find use in lists of options.
The HTML to make radio buttons is a composite tag. By this I mean that the tag has several (three in this case) attributes that must be included.
The complete HTML tag looks like this: <input type=radio name=button_name value=value_name>Without these attributes, the radio button you so desire will appear as a text box, will not relate itself to any part of the script, and will not supply any information. Do you remember the example above that showed you how to make text appear by default inside a textbox? If you recall, you used the value attribute. In the
case of a radio button, the value replaces any text that would have been typed into a text box. For all of you visual learners out there, the following HTML snippet: <input type=radio name=favorite value=ford>Ford<input type=radio name=favorite value=chevy>Chevy<input type=radio name=favorite value=dodge>DodgeGenerates this series of Radio Buttons: Play around with the above buttons for a second....notice that you can't select more than one? That's because they all have the same "name=" attribute, and therefore are all connected to one another. This also tells the CGI script that all of the buttons apply to the same section of the script. The last attribute that can be applied to Radio Buttons is "checked". By adding this to one of the Check BoxesThe check box is most often used when there is only a single option related to a section of your form; such as "Check here if you never want to hear from me again". The
HTML is basically the same as a Radio Button, save that the value of "type=" should be "checkbox". Therefore, the following HTML: <input type=checkbox name=never value=true>Check here if you never want to hear from me again.Creates the following result: The "checked" option can also be applied to check boxes: Drop-Down Menus & Selection BoxesThese little beauties are best placed when you have a finite number of resposes to a question, but to many to use Radio Buttons or Check Boxes. The HTML tags used to generate these
menus are Just like any other form item, a menu must have a name= attribute. The value= in this case is replaced by the choices in the menu; which are generated by a separate tag.
The tag you need is <option>Text</option>The last tag, </option> is, simply put, optional (If that doesn't make your head spin). The HTML will function perefctly well without it, but I would still recommend you include it for
the sake of completeness.
Now lets review the types of menus one by one. If you add no attributes (other than name=) to the By typing the word multiple inside the Sometimes you may have a limited amount of space for a long list of options; the answer to this dilema is adding a scrollbar to the menu. This feat is accomplished using the size= attribute. The value attached to this attribute is a number of options that will be visible in the box. Should the number of options exceed the number of rows, a scrollbar will appear on the right side of the menu. The Submit & Reset ButtonsOn almost every form, you will see buttons at the bottom that (typically) offer to sumbit your input or reset the form. The functions of these two should be plainly obvious. How to create them however, may not be.
This is yet another use for the ever-popular
Creating a reset button is simply a matter of changing the value of the type= attribute as follows: <input type="reset">. This will reset everything between <form> and </form> to the default values.The result looks like this: If the button you wish to create is not a send or clear button, then make the value of type= "button". Don't for get to add the name= attribute, or your buttons will do nothing but take up space. If you want to change the word or words that appear on the face of the button, use the value= attribute. Like any other attribute, as long as the
value is in quotes, spaces are okay. Invisible ValuesI can already hear you asking "Invisible values? What's the point of that". Before you discredit me as a crackpot however, I ask you to hear me out. Now then....let us suppose that you need to track the source information you recieved from a form you created. With invisible values, you can add information that will be sent every time the form is completed. The end-user of the form has absloutely no control over the value associated with this part of the form, so you could enter the URL of the page the form can be found on. That way whenever you recieve input from the form, you will be able to tell which page it came from with no guesswork involved! For any system administrator, that would be great news indeed.... This item is the final use for the<input> tag; in this case, the type= and value= attributes are required; you can add name= if you wish. This would be a very good idea if you have more than one
invisible value on your form. The HTML invloved looks like this:<input type="hidden" name="Invisible" value="You can't see me!!">Obviously, I can't show you an example of what an invisible value looks like; you'll just have to trust me. | |