[prev] [index] [next]

Generating Forms (cont)

Example (self-invoking form):

#!/usr/bin/perl
# CGI script that creates a fill-out form
# and echoes back its values.

use CGI qw/:standard/;  # qw/X/ == 'X'
print header,
   start_html(-bgcolor=>'white','A Simple Example'),
   h1(font({-color=>'blue'},'A Simple Example')),
   start_form,
   "What's your name? ",textfield('name'),p,
   "What's the combination?", p,
   checkbox_group(-name=>'words',
                  -values=>['eenie','meenie','minie','moe'],
                  -defaults=>['eenie','minie']), p,
   "What's your favorite color? ",
   popup_menu(-name=>'color',
              -values=>['red','green','blue','yellow']),p,
   submit,
   end_form,
   hr;

if (param()) {
   print "Your name is ",em(param('name')),p,
      "The keywords are ",em(join(", ",param('words'))),p,
      "Your favorite color is ",em(param('color')),
      hr;
}