#!/usr/bin/perl
#
# eg3: produce a working form using CGI
#
use strict;
use warnings;

use CGI;

my $cgi = CGI->new; 
print $cgi->header,
      $cgi->start_html('A trivial form'),
      $cgi->h1('A trivial form'),
      $cgi->start_form,
      'Enter your name:', $cgi->textfield('name'), $cgi->p,
      'Select your level of Perl expertise:',
      $cgi->popup_menu(
         -name => 'expertise',
         -values => ['Newbie', 'Adequate', 'Guru', 'Larry']
      ), $cgi->p,
      $cgi->submit,
      $cgi->defaults('Clear'),
      $cgi->end_form;

my %response = ( Newbie => "Get on with it then!",
                 Adequate => "One day you too may wear sunglasses, my son",
                 Guru => "Pretty cool sunglasses.",
                 Larry => "We bow before your godlike powers!"
               );
if( $cgi->param )
{
        # Process form parameters...
        my $name = ucfirst( lc( $cgi->param('name') ) );
        my $expertise = $cgi->param('expertise');
        my $msg = $response{ $expertise } || "umm?";
        print $cgi->hr, "Hello, $name the $expertise - $msg";
}

print $cgi->end_html;
