Illustrating Hidden Fields
#!/usr/bin/perl -w

#####  Illustration of hidden fields.  Remember that widgets create
#####  parameters that last for only ONE program invokation.  
#####  Here's a program which will illustrate how to keep parameters alive!!

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);

print header;
print start_html("Illustrating Hidden Fields!");

if (!param)
{
    print start_form,
          p("Favorite Color: ",  textfield("color")),
          p("Favorite Name:",    textfield("name")),
          submit("Enter favorites"),
          end_form;
}
elsif (param("Enter favorites"))
{
    $color  = param("color");
    $name   = param("name");
    $color  = uc($color);
    $name   = uc($name);
####  When you want to save the CHANGED value of a param from a previous
####  invokation, you must use -value to override the value from that
####  previous invokation and -override to make the new value "stick".
####  Remember, form elements are "sticky"!!!
    print start_form,
          hidden(-name => "color", -value => $color, -override => 1),
          hidden(-name => "name",  -value => $name,  -override => 1),
          submit("Save hidden fields"),
          end_form;
}
elsif (param("Save hidden fields"))
{
    print p("Color: ", param("color")),
          p("Name:  ", param("name"));
}

    
print end_html;