package My::App; use Dancer ':syntax'; use CGI qw(:all); our $VERSION = '0.1'; # Initial variables my @chars = ("A".."Z", "a".."z", "0".."9"); my $randomString; $randomString .= $chars[rand @chars] for 1..8; my @languages = ("English", "Francais"); my @colours = ("Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet", "Black"); get '/' => sub { session random_str => $randomString; my $random_str = session 'random_str'; my $file = "$random_str.txt"; return start_html() . h2("Welcome to this basic form") . start_form( -action => 'select_color', -method => 'GET' ) . popup_menu({ -name => "language", -values => \@languages, -default => $languages[0] }) . p("The randomly generated string is: $random_str
The filename is: $file") . submit({-value => "Continue"}) . end_form() . end_html() ; }; get '/select_color' => sub { my $random_str = session 'random_str'; my $file = "$random_str.txt"; return start_html() . h2("Part Two") . start_form( -action => 'select_animal', -method => 'GET' ) . p("The randomly generated string is: $random_str
The filename is: $file") . hidden({ -name => "language", -value => params->{language} }) . "

Please choose your favourite colour:

" . radio_group({ -name => "colour", -values => \@colours, -default => $colours[0], -linebreak => "true" }) . submit({-value => "Continue"}) . end_form() . end_html() ; }; get '/select_animal' => sub { my $random_str = session 'random_str'; my $file = "$random_str.txt"; return start_html() . h2("Almost Done!") . start_form() . p("The randomly generated string is: $random_str
The filename is: $file") . hidden({-name => "language", -value => params->{language}}) . hidden({-name => "colour", -value => params->{colour}}) . p("Thanks for your help!") . end_form() . end_html() ; }; true;