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 elements ”the design ”of the form. Radio buttons , text fields, and pull-down menus (also called pop-up menus ) are just a few of the ways you can gather input. It's perfectly OK 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 in Section 11.3.3). 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 input ”what 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. 11.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, and 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 languages ”Perl, C, C#, Visual Basic, VBScript, JavaScript, Java, Cold Fusion Markup Language, PHP ”and may be part of a dedicated application server like Macromedia's Cold Fusion Server or Microsoft's Active Server Page 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 it ”whatever 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 itself ”a 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 MX, of course. Part VI 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, Cold Fusion, 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 inhouse 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 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. |