QuickRead 17: Forms
| What is a Form? | |||||||
| Forms are a way of getting information from the person
viewing your web page. A user (for this QuickRead by user we mean someone viewing
your webpage, not you as the person creating the webpage) inputs things into the
form and it is sent to the web server. There are two parts to any form. First
there is the html part that involves making the input boxes and buttons for the
user. The second part is the script, or program, which is on the server. The script
is a program that runs on the server and processes the information from the user.
Web based scripts are commonly written in Java, Javascript, Perl, or C. We will not
be teaching you how to write scripts, only how to write the form code for other
scripts to use. If you are interested in learning scripting we suggest you look into
a programming course for Java, Perl, or C++ or search the Internet for free
tutorials (there are a lot out there).
We use several forms in this class to get information from you. The box at the bottom of these tutorials (get behind the wheel) that allows you to enter in code is an example of a form. Other forms you have seen for this class include: Addme, parts of MAX, and Webgrades. Outside of this class, you have seen them on search engines and they are used in E-commerce (Internet sales) in large amounts. | |||||||
.
| .
| The <form> Tag
| The <form> tag is very similar to the other tags you
have learned. An HTML form begins with a <form> tag and ends with a
</form>. You can have more than 1 form on a page, but that means you may need
more than 1 scripts and you need multiple "submit" buttons (more on that later) and
it is generally not a good idea. Between the form and /form tags you can put most
any normal html
code (to change fonts, bold,
<br>, etc), usually used to format the input boxes and buttons in an organized
fashion. A form can be placed anywhere between the <body> and </body> tags (it
doesn't go in the head section at the top like Javascript). There are two attributes
for the <form> tag: action and method. The method attribute has a value of either
"post" or "get", and determines how the form and the script will communicate. The
method attribute doesn't affect how the form looks on the web, it only affects the
interface and protocol between the form and the script.
| The "action" attribute on the <form> tag is very important. Its value is a URL that tells the webpage where the script to run for this form is located (like action="http://some_website.com/somescript"). Don't worry about the script writing now--just know that the "action" attribute allows a form to designate which script to run for the form. The script isn't executed (meaning the program isn't run) until the user presses the "submit" button (but we'll get to that in a bit). For example: <form action="http://grove.ufl.edu/tutorial/mc17.cgi" method=post>. This tells the browser that the script to run is "mc17.cgi" located in the "tutorial" directory. The guts of the form are in the tags that occur inbetween the <form ..> tag and </form> tag. The cgi extention (on mc17.cgi) signifies that this is a "Common Gateway Interface" file (similar to how .html in index.html signifies that it is a webpage file). Don't worry too much about the details--just know that "cgi" tells the server that this file is a script (or program), and that it will be executed from the web. CGI is the interface between web pages and scripts and is how the information gets from the webpage form elements into the script to be processed. A form allows people to transfer information to the script through CGI. The URL to a script for a form will often contain directories with names like "cgiwrap" or "cgi-bin". This is just a fairly common practice that helps organize files. .
| .
| The Guts--Input tag
| First we'll deal with the <input> tag, as it is the
most commonly used tag and can do alot for us. It defines a place for the user to to
input some type of information. It has an attribute called type that defines which
kind of input the user can provide. The valid values for the type attribute are:
| |
| Index |
| 12 | 15 | 16 | 17 | 18 |