Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^8: obtaining yyyy-mm-dd via a calendar object

by Asim (Hermit)
on Aug 04, 2006 at 13:40 UTC ( [id://565649]=note: print w/replies, xml ) Need Help??


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

you get my award for most 'novice' friendly thus far...much thanks

You’re quite welcome! Please keep in mine – a lot of the folks here are happy to help, and we’re just trying to guide you to finding your own solutions. As volunteers, we give it the time we have, and if there’s frustration, it’s often not due to meanness, just a wish for people to meet us half-way with questions.

Asking for broad-ranged aid on a situation is likely to led people to believe you wish tutoring, not aid on a specific topic; you can read the excellent Understanding and Using PerlMonks for more on how to ask questions 'round here. Does that put some of the reactions into perspective?

does php allow you the same flexibility as perl? i see courses in the adult ed for php, but nothing on perl

You do like the tough questions, don't you? :)

PHP is a distant relation to Perl, focused on publishing web pages. I confess to not having made anything with if, just editing and fiddling with a couple of pre-made apps, like Wordpress, that use PHP.

At a jump, and not to start another PHP vs. Perl flamewar, I'm going to say my impression is that PHP is very popular, in part because it’s easier to write websites in PHP as opposed to standard Perl -- although modules like Embperl offer very similar functionality -- and about the same level of basic connect-to-database extensions/modules as Perl. PHP seems to lack depth in the quantity and quality of Modules, as well as being somewhat more difficult to build extensive and complex web applications in.

I understand that PHP has something similar to Perl's taint mode, as well as the SQL-injection-resistant placeholder ability of DBI; their maturity, in comparison to Perl's years of experience (tainting has been a part of Perl since before the World Wide Web was created, much less CGI), is unknown to me. These aspects are, to me, critical in any Internet-facing web application.

To sum up: PHP is worth a try, and is currently far more popular than Perl -- yet it’s not nearly as flexible as Perl. Yet taking a good course on PHP beats out not learning anything by a country mile. :)

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

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

Replies are listed 'Best First'.
Re^9: obtaining yyyy-mm-dd via a calendar object
by gmacfadden (Sexton) on Aug 21, 2006 at 01:02 UTC
    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;
      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.

        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 CalendarWidget.pm 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('http://www.gmacfadden.com/cgi-bin/Calendar/Calend +arWidget.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 => "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"); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://565649]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 06:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found