From: Kirrily R. <sk...@us...> - 2001-10-10 18:02:12
|
Update of /cvsroot/formmagick/formmagick/lib/CGI/FormMagick In directory usw-pr-cvs1:/tmp/cvs-serv32118/lib/CGI/FormMagick Modified Files: Utils.pm Log Message: Moved a couple of routines out to Utils.pm Index: Utils.pm =================================================================== RCS file: /cvsroot/formmagick/formmagick/lib/CGI/FormMagick/Utils.pm,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -r1.10 -r1.11 *** Utils.pm 2001/10/10 17:53:04 1.10 --- Utils.pm 2001/10/10 18:02:09 1.11 *************** *** 237,240 **** --- 237,324 ---- } + =head2 finished + + Figures out whether the user's finished. This could be because they + clicked "Finish" or it could be because they were on the last page and + hit enter. + + This bears the same relationship to is_last_page as just_starting does to + is_first_page. + + =begin testing + + use CGI; + + $cgi = CGI->new( { Finish => 1 } ); + local $fm->{cgi} = $cgi; + ok($fm->finished(), "User is finished (clicked Finish)"); + + $cgi = CGI->new(""); + local $fm->{cgi} = $cgi; + local $fm->{page_number} = 2; + ok($fm->finished(), "User is finished (last page, pressed enter)"); + + $cgi = CGI->new(""); + local $fm->{cgi} = $cgi; + local $fm->{page_number} = 1; + ok(!$fm->finished(), "User is NOT finished (not last page, pressed enter)"); + + $cgi = CGI->new({ Previous => 1 }); + local $fm->{cgi} = $cgi; + local $fm->{page_number} = 2; + ok(!$fm->finished(), "User is NOT finished (last page, didn't press enter)"); + + =end testing + + =cut + + sub finished { + my $self = shift; + return 1 if $self->{cgi}->param("Finish"); + return 1 if $self->user_pressed_enter() and $self->is_last_page(); + return 0; + } + + =head2 user_pressed_enter() + + A weirdness in the HTML spec and/or + browser implementations thereof means that hitting "enter" on a + single-text-field form will submit the form without any value + being passed. Worse yet, at least one browser is reported to + automatically choose the first submit button on the form, in our + case "Previous", which is just WRONG but I can't see any way to + work around that. + + So this routine tells you if the user just hit enter. Returns 1 if they + did, or 0 otherwise. + + =begin testing + + use CGI; + + my $cgi = CGI->new(""); + local $fm->{cgi} = $cgi; + ok($fm->user_pressed_enter(), "User pressed enter"); + + $cgi = CGI->new({ Next => "foo" }); + local $fm->{cgi} = $cgi; + ok(!$fm->user_pressed_enter(), "User clicked a button"); + + =end testing + + =cut + + sub user_pressed_enter { + my $self = shift; + unless ( $self->{cgi}->param("Previous") or + $self->{cgi}->param("Next") or + $self->{cgi}->param("Finish") ) { + return 1; + } else { + return 0; + } + } + + =head2 $fm->form() |