7.8 Form Widget MethodsThe here document, though handy, may not be the best way to build every HTML page. CGI.pm provides several other methods to create widgets, including:
The following example, /var/www/cgi-bin/widgets3.cgi , uses these methods and produces the same form shown in Figure 7.12. You can find its code at http://localhost/cgi/widgets3.cgi or www.opensourcewebbook.com/cgi/widgets3.cgi. To prove it works, load one of the URLs. The if part is just like widgets2.cgi , so we won't show it here. The else part is of interest here: }else{ # if we are here, then we need to build the form # so print the header, then the html print header(), start_html(-title => An Example of Form Widgets, -bgcolor => #ffffff), h1(An Example of Form Widgets), start_form(), Programming language: , textfield(-name => language, -value => Perl), br(), Comments:, br(), textarea(-name => comments, -cols => 20, -rows => 5), br(), Rate the coolness: , radio_group(-name => coolness, -values => [cool, very cool, ice cold], -default => ice cold), br(), I will learn more about Perl and CGI: , checkbox(-name => learnmore, -value => yes, -label => Yes, -checked => 1), br(), I will use this operating system: , popup_menu(-name => operating_system, -values => [Linux, Solaris, HPUX], -size => 1), br(), My favorite animal(s): , scrolling_list(-name => animal, -values => [Penguin, Camel, Llama, Panther], -size => 3, -multiple => 1), br(), br(), submit(-value => Submit Form), , reset(-value => Reset Form), end_form(); } Here the various CGI.pm functions are used to produce the HTML for this form. N Notice that action="/cgi-bin/widgets.cgi" was not set in the start_form() method. CGI.pm is smart enough to set the action to the name of the CGI program it is used within. CGI.pm offers these other methods to create form widgets:
See the CGI.pm documents for further information. |