Section 10.1. Form Basics

10.1. Form Basics

A form begins and ends with the HTML <form> tag. The opening <form> tag indicates the beginning of the form and sets its properties; the closing </form> tag, of course, marks the form's end.

In between these tags, different objects provide the basic user -interface elementsthe designof the form. Radio buttons , text fields, and pull-down menus are just a few of the ways you can gather input. It's perfectly okay to include other HTML elements inside a form, too. In fact, your site's visitors would be lost if you couldn't also add (and format) text that explains the purpose of each form object. And if you don't use a table or Cascading Style Sheets to lay out a form in an organized way, it can quickly become an unreadable mess (see the box on Section 10.3.5).

Every form element, whether it's a text field or a checkbox, has a name and a value . The name indicates what information the element is intended to collect. For example, if you want your visitors to type their email address into a text field, the name of that field might be email . The value, on the other hand, is the person's inputwhat your visitors type into the text field, for example, or the selections they make from a pull-down menu.

After your visitors fill out the form and click the Submit button to transmit their responses, each form element is transmitted as a name/value pair like this: email =bob@bobville.com. Submitting both pieces of information helps the program that processes the form figure out what the input means. After all, without a name, a value of 39 doesn't mean much (39 what? Potatoes, steps, days until Christmas?). The name/value pair (age=39) provides context for a visitor's input.

10.1.1. The Code Backstage

Creating a form is just the first step in collecting information from your Web site's visitors. You also need to connect the form to a computer program that actually does something with the information. The program may simply take the data from the form and email it to you. However, it could do something as complex as contacting a bank, processing a credit card payment, creating an invoice item, or notifying a shipping department to deliver the latest Stephen King novel to someone in Nova Scotia. A form is pretty useless without a program like this running on the Web server. These information- crunching programs come in a variety of languagesPerl, C, C#, Visual Basic, VBScript, JavaScript, Java, ColdFusion Markup Language, PHPand may be part of a dedicated application server like Macromedia's ColdFusion Server or Microsoft's Active Server Pages technology.

Writing the necessary behind-the-scenes processing software can be complex, but the concepts behind forms are straightforward:

  • First, someone fills out a form on your Web page and clicks the Submit button.

  • Next, the form data is transmitted over the Internet to a program on your Web server.

  • The program collects the data and does something with itwhatever you and the programmer decide it should do.

  • Finally, the Web server returns a page to the Web visitor. It may be a standard Web page with a message like "Thanks for the info ," or a page dynamically generated by the program itselfa detailed invoice page, for example.

So how do you create the processing half of the forms equation if you're not a programmer? You can use Dreamweaver, of course. Part Six of this book describes Dreamweaver's dynamic Web building tools for creating pages that use information collected from forms in a database. If your Web server accommodates Active Server Pages, ASP.NET, ColdFusion, Java Server Pages, or PHP, Dreamweaver can create form-processing programs for you.

If you're part of a Web development team in a company, you may already have in-house programmers who can help you create the processing program.

Furthermore, even if your Web hosting company doesn't tolerate any of the application servers that work with Dreamweaver, they probably offer free form-processing programs as part of their services. Contact your Web host and ask about this. If so, the company will provide instructions on how to use these programs.

Finally, if you feel adventurous, many form-processing programs are available for free on the Web. For a thorough sampling, see the CGI Resource Index at http://cgi.resourceindex.com. Using these free programs can be tricky, however, because you need to download the appropriate program and install it on your Web server. Your Web hosting company may not even permit you to do so.



Dreamweaver 8[c] The Missing Manual
Dreamweaver 8[c] The Missing Manual
ISBN: 596100566
EAN: N/A
Year: 2006
Pages: 233

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net