Hi Asim, OK, I'm back, a little beaten up, but much wiser. I have built a calendar widget from scratch using the Calendar::Simple pm. The prg is tested and works predictably (correctly as far as I can tell). When the program is invoked, a calendar for the current month is displayed. The user is allowed to pick a day, or select the previous or next month as desired. When the user selects a day, the program returns the yyyy-mm-dd as a string.
I would like some advice on how to bridge the final gap. How do I get this calendar widget to work within a CGI form?
# Calendar widget program. Creates pop-up calendar to select a date. package CalendarWidget; use strict; #force all variables to be declared before use use CGI qw(:standard escape escapeHTML); # most common CGI interface f +unctions use CGI::Carp qw(warningsToBrowser fatalsToBrowser); #all diags to bro +wser use Calendar::Simple; my $requested_new_month = param("requested_new_month"); my $specific_date_was_selected = param("specific_date_was_selected"); my $yyyy = param("yyyy"); my $mm = param("mm"); my $dd = param("dd"); sub calendar_widget { ####### dispatching logic begins here if (defined (param("specific_date_was_selected"))) #spec date was sele +cted { if ($specific_date_was_selected eq "specific_date_was_selected") {return($yyyy,$mm,$dd);} # return selected date to calling pr +ogram else {} } elsif (defined (param("requested_new_month"))) # if request not curren +t mo & yr { if ($requested_new_month eq "previous_month") # requested previous +_month { # adjust calendar backward in time if ($mm eq "1") # if previously displayed month was January { $mm = 12; # change new displayed month to December $yyyy = $yyyy-1; # and adjust year } else # for all other months {$mm = $mm-1; } #change new displayed month to previous mon +th } else # requested_new_month was next_month { # adjust calendar forward in time if ($mm eq "12") # if previously displayed month was December { $mm = 1; # change new displayed month to January $yyyy = $yyyy+1; # and adjust year } else { $mm = $mm+1; } #change new displayed month to next month } show_calendar($mm, $yyyy); #show the revised calendar } else { show_calendar(); } #show calendar using current month / year } ####### dispatching logic ends here sub show_calendar { my ($specified_month, $specified_year) = @_; #get passed parms from ca +lling pgm my (@month, @row, @calendar_table_entry, @array, $array, $url1, $url2, + $theTime); my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my @weekDays = qw (Sun Mon Tue Wed Thu Fri Sat); my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfW +eek, $dayOfYear, $daylightSavings, $year) = localtime(); $year = 1900 + $yearOffset; $theTime = "$weekDays[$dayOfWeek], $months[$month] $dayOfMonth, $year +$hour:$minute:$second"; my @month_names = qw(January February March April May June July August + September October November December); if (($specified_month eq '') || ($specified_year eq '')) #if no date s +pec'ed { @month = calendar($month+1, $year); # uses ACTUAL # of month & yea +r $specified_month = $month+1; $specified_year=$year; } else # (month / year info were spec'ed, get info for specified month / + year { @month = calendar($specified_month, $specified_year); } $url1 = url().sprintf("?requested_new_month=%s&yyyy=%s&mm=%s",escape(" +previous_month"),escape($specified_year),escape($specified_month)); $url2 = url().sprintf("?requested_new_month=%s&yyyy=%s&mm=%s",escape(" +next_month"),escape($specified_year),escape($specified_month)); push (@row,qq(<table border=3 bordercolor="red" align="left" bgcolor=" +x00ffff">) ); my $i=0; my $j=0; @array = @weekDays; $array = param('@array'); push (@row, Tr ( ( qq(<TD ALIGN="CENTER" VALIGN="CENTER", COLSPAN="7">), qq(<FONT CO +LOR=#FF0000>), "$theTime", qq(</FONT>) ) ) ); push (@row, Tr ( ( qq(<TD ALIGN="LEFT" VALIGN="CENTER", COLSPAN="1">), qq(<FONT COLO +R=#0000FF>), (a({-href=>$url1},"<<")), qq(</FONT>) ), ( qq(<TD ALIGN="CENTER" VALIGN="CENTER", COLSPAN="5">), qq(<FONT CO +LOR=#0000FF>), "@month_names[$specified_month-1] $specified_year", qq +(</FONT>) ), ( qq(<TD ALIGN="RIGHT" VALIGN="CENTER", COLSPAN="1">), qq(<FONT COL +OR=#0000FF>), (a({-href=>$url2},">>")), qq(</FONT>) ) ) ); foreach $array(@array) # specify calendar days of week { @calendar_table_entry[$j] = $array; $i++; $j++; } $j=0; push (@row, Tr ( ( qq(<TD ALIGN="RIGHT" VALIGN="CENTER", COLSPAN="1">), @calendar_ta +ble_entry[$j] ), td (@calendar_table_entry[$j+1]), td (@calendar_tabl +e_entry[$j+2]), td (@calendar_table_entry[$j+3]), td (@calendar_table +_entry[$j+4]), td (@calendar_table_entry[$j+5]), td (@calendar_table_ +entry[$j+6]) ) ); foreach (@month) { $j=0; @array = @$_; foreach $array(@array) # specify calendar numbered days in month { @calendar_table_entry[$j] = $array; $i++; $j++; } $j=0; push (@row, Tr ( ( qq(<TD ALIGN="CENTER" VALIGN="CENTER">), qq(<FONT COLOR=#FF0000>) +, (a({-href=>url().sprintf("?specific_date_was_selected=%s&yyy +y=%04d&mm=%02d&dd=%02d", escape("specific_date_was_selected"), escape +($specified_year), escape($specified_month), escape(@calendar_table_e +ntry[$j]))}, @calendar_table_entry[$j])), qq(</FONT>) ), ( qq(<TD ALIGN="CENTER" VALIGN="CENTER">), (a({-href=>url().sprintf +("?specific_date_was_selected=%s&yyyy=%04d&mm=%02d&dd=%02d", escape("specific_date_was_selected"), escape($specified_year), escape( +$specified_month),escape(@calendar_table_entry[$j+1]))}, @calendar_ta +ble_entry[$j+1]))), ( qq(<TD ALIGN="CENTER" VALIGN="CENTER">), (a({-href=>url().sprintf +("?specific_date_was_selected=%s&yyyy=%04d&mm=%02d&dd=%02d", escape("specific_date_was_selected"), escape($specified_year), escape( +$specified_month), escape(@calendar_table_entry[$j+2]))}, @calendar_t +able_entry[$j+2]))), ( qq(<TD ALIGN="CENTER" VALIGN="CENTER">), (a({-href=>url().sprintf +("?specific_date_was_selected=%s&yyyy=%04d&mm=%02d&dd=%02d", escape("specific_date_was_selected"), escape($specified_year), escape( +$specified_month), escape(@calendar_table_entry[$j+3]))}, @calendar_t +able_entry[$j+3]))), ( qq(<TD ALIGN="CENTER" VALIGN="CENTER">), (a({-href=>url().sprintf +("?specific_date_was_selected=%s&yyyy=%04d&mm=%02d&dd=%02d", escape("specific_date_was_selected"), escape($specified_year), escape( +$specified_month), escape(@calendar_table_entry[$j+4]))}, @calendar_t +able_entry[$j+4]))), ( qq(<TD ALIGN="CENTER" VALIGN="CENTER">), (a({-href=>url().sprintf +("?specific_date_was_selected=%s&yyyy=%04d&mm=%02d&dd=%02d", escape("specific_date_was_selected"), escape($specified_year), escape( +$specified_month), escape(@calendar_table_entry[$j+5]))}, @calendar_t +able_entry[$j+5]))), ( qq(<TD ALIGN="CENTER" VALIGN="CENTER">), qq(<FONT COLOR=#FF0000>) +, (a({-href=>url().sprintf("?specific_date_was_selected=%s&yyyy=%04d& +mm=%02d&dd=%02d", escape("specific_date_was_selected"), escape($specified_year), escape( +$specified_month), escape(@calendar_table_entry[$j+6]))}, @calendar_t +able_entry[$j+6])), qq(</FONT>) ) ) ); } print table (@row); return(); } 1;

In reply to Re^9: obtaining yyyy-mm-dd via a calendar object by gmacfadden
in thread obtaining yyyy-mm-dd via a calendar object by gmacfadden

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.