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

How do I get this calendar widget to work within a CGI form?

At a first glance, you need to feed the response into a form variable, so that when you submit the form, the calendar information will be passed into the CGI paramters sent to the form's action target. You'd likely feed the response to the variable via Javascript, but the rest is bog-standard HTML form work.

Does that make sense? Sorry if it's short, I just got back from vacation...

----Asim, known to some as Woodrow.

  • Comment on Re^10: obtaining yyyy-mm-dd via a calendar object

Replies are listed 'Best First'.
Re^11: obtaining yyyy-mm-dd via a calendar object
by gmacfadden (Sexton) on Aug 21, 2006 at 20:25 UTC
    Welcome back from what is hoped was a relaxing break. OK, we're almost there! Without changing the calendar widget code from Reply 9 in the previous thread, following is the code used to implement your suggestion.
    When the below code executes, it results in an internal server error. Interpreting this to mean that code is not finding the perl module. Can you discern what my problem could be?
    #! /usr/bin/perl -wT # 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 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(''); my $url_picture = URI->new(' +jpg'); my @field_list = ({ name => "selected_date", label => "Select a date:" }); print header (), start_html (-title => "Test CGI Form", -bgcolor => "o +range"); 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 "<br>You selected $y1-$m1-$d1.<br>\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(<table border=3 bordercolor="blue" align="left" + bgcolor="xffff00">) ); push (@row, Tr ( ( qq(<TD ALIGN="CENTER" VALIGN="TOP" BGCOLOR="yellow" COLSPAN="2">) +, qq(Please provide the information requested in the table below.) ) ) ); push (@row, Tr ( ( qq(<TD ALIGN="RIGHT" VALIGN="TOP">), qq(Select a date:) ), ( qq(<TD ALIGN="LEFT" VALIGN="TOP" BGCOLOR="yellow">), (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.<br>\n"); }