#! /usr/bin/perl -wT # use strict; #force all variables to be declared before use use CGI qw(:standard escape escapeHTML); # most common CGI interface functions use CGI::Carp qw(warningsToBrowser fatalsToBrowser); #all diags to browser use URI; use lib qw(/home/gmacfadd/public_html/cgi-bin/Calendar); use CalendarWidget; my $selected_date; my ($get_calendar_widget, $item); my $choice = lc (param ("choice")); # get choice, lowercased my $url1 = URI->new('http://www.gmacfadden.com/cgi-bin/Calendar/CalendarWidget.pm'); my $url_picture = URI->new('http://www.gmacfadden.com/images/calendar.jpg'); my @field_list = ({ name => "selected_date", label => "Select a date:" }); print header (), start_html (-title => "Test CGI Form", -bgcolor => "orange"); if ($choice eq "") # initial script invocation { display_entry_form (); } elsif ($choice eq "submit") { process_form (\@field_list); } elsif (defined (param("get_calendar_widget"))) { if ($get_calendar_widget eq "get_calendar_widget") { if ($item eq "item1") { my($y1,$m1,$d1)= CalendarWidget::calendar_widget(); print "
You selected $y1-$m1-$d1.
\n"; $selected_date = $y1."-".$m1."-".$d1; } else {} } else { } } else { print p (escapeHTML ("Logic error, unknown choice: $choice")); } print end_html (); exit (0); sub display_entry_form { my @row; # define array print start_form (-action => url ()); #default method is POST push (@row, qq() ); push (@row, Tr ( ( qq(
), qq(Please provide the information requested in the table below.) ) ) ); push (@row, Tr ( ( qq(), qq(Select a date:) ), ( qq(), (textfield (-name => "selected_date", -size => 10)), a({-href=>$url1}, img({-src=>"$url_picture", -alt=>"click calendar to select a date"}) ) ) )); print table (@row), submit (-name => "choice", -value => "Submit"), end_form (); } sub process_form { my $field_ref1 = shift; # reference to field-List my @errors; $selected_date = param ('selected_date'); foreach my $f (@{$field_ref1}) { if ( ($f->{name} eq "selected_date") ) { push (@errors, $f->{label}) if $selected_date eq ""; #it's empty! } else { } } if (@errors) { print p ("Some information is missing." . " Please fill in the following fields:"); s/:$// foreach (@errors); # strip colons from end of labels print ul (li (\@errors)); # print column names display_entry_form (); # redisplay entry form return; } print p ("The date entered was $selected_date.
\n"); }