alen129 has asked for the wisdom of the Perl Monks concerning the following question:

I've created a CGI form using perl, everything works really good, except I'm having a hard time finding a solution as to how I can get the current time and date filled in the form while giving the user the option to change the input with a date and time picker. here is pieces of code I've written:

sub output_form { my ($q) = @_; print $q->start_form( -name => 'main', -method => 'POST', ); print $q->start_table; print $q->Tr( $q->td('Update#:'), $q->td( $q->textfield(-name => "update_num", -size => 02) ) ); print $q->Tr( $q->td('Date:'), $q->td( $q->textfield(-name => "date", -size => 50) ) ); print $q->Tr( $q->td('Time:'), $q->td( $q->textfield(-name => "time", -size => 50) ) );
  • Comment on Perl CGI Date and Time picker with auto populate with current date and time
  • Download Code

Replies are listed 'Best First'.
Re: Perl CGI Date and Time picker with auto populate with current date and time
by kcott (Archbishop) on Sep 14, 2016 at 22:15 UTC
Re: Perl CGI Date and Time picker with auto populate with current date and time
by hippo (Archbishop) on Sep 14, 2016 at 22:39 UTC

    First of all, please have a read of HTML Generation functions should no longer be used in the documentation for CGI. The tone of that section should hopefully convince you not to use them in any new code.

    As to the question itself, the general approach would be:

    1. Obtain the current date and time using your favourite function or module.
    2. Insert these as the default values in a number of select fields or better yet, an HTML5 datetime field.

    Are you able to do either of these or neither? What have you tried? How did it fail to meet your needs?