2 post forms in 1 webpage is not working as expected
i have form_1, form_2, each displays a value in text box.
the problem is, 1. click "submit", the 2nd text box shows "1", 2. click "next page", now that "1" is reset to "0". is there a why these 2 buttons won't affect each other ? |
#!/usr/bin/perl -w
BEGIN { push @INC, "/usr/share/perl5"; } BEGIN { push @INC, "/usr/share/perl5/CGI"; } # # Modules # use strict; use warnings; use CGI; # use CGI::Carp qw(fatalsToBrowser); # # Subroutine Prototypes # sub output_top($); sub output_end($); sub display_results($); sub form_1($); sub form_2($); my $q1 = new CGI; print $q1->header(); # Output stylesheet, heading etc output_top($q1); display_top($q1); # Output footer and end html output_end($q1); exit 0; #------------------------------------------------------------- # Outputs the start html tag, stylesheet and heading sub output_top($) { my ($q) = @_; print $q->start_html( -title => 'Test' ); print $q->h4("Display Options"); } # Outputs a footer line and end html tags sub output_end($) { my ($q) = @_; print $q->div("My Web Form"); print $q->end_html; } ############################################## # Displays the results of the form sub display_top($) { my ($q) = @_; my $recPerPage = $q->param('records_per_page'); my $sortOpt = $q->param('sort_options'); form_1($q); print $q->hr(); # updates print $q->h4("First record on page"); print $q->textfield(-name => "first_record_on_page", -size => 50, -value=>$recPerPage+0); form_2($q); print $q->h4("Hi $recPerPage"); print $q->p("$sortOpt records per page."); my $fVal = $q->param('rsubmit'); print $q->h5($fVal); } ############################################## # Outputs a web form sub form_2($) { my ($q) = @_; print $q->start_form( -name => '2main', -method => 'POST', ); print $q->start_table; print $q->Tr( $q->td($q->submit(-name=>'rsubmit', -value => 'Previous page')), $q->td($q->submit(-name=>'rsubmit', -value => 'Fresh')), $q->td($q->submit(-name=>'rsubmit', -value => 'Next page')), $q->td(' ') ); print $q->end_table; print $q->end_form; } ############################################## # Outputs a web form sub form_1($) { my ($q) = @_; print $q->start_form( -name => 'main', -method => 'POST', ); print $q->start_table; print $q->Tr( $q->td('Records per Page') ); print $q->Tr( $q->td( $q->textfield(-name => "records_per_page", -size => 10, -value=>1) ) ); print $q->end_table; print $q->start_table; print $q->Tr( $q->td($q->submit(-name=>'bsubmit', -value => 'Submit')), $q->td($q->reset(-name=>'bsubmit', -value => 'Reset')), $q->td(' ') ); print $q->end_table; print $q->end_form; } |
All times are GMT -5. The time now is 04:04 AM. |