LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-18-2012, 04:18 PM   #1
5883
Member
 
Registered: Aug 2004
Posts: 173

Rep: Reputation: 0
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 ?
 
Old 07-18-2012, 04:19 PM   #2
5883
Member
 
Registered: Aug 2004
Posts: 173

Original Poster
Rep: Reputation: 0
#!/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;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Wget webpage with multiple forms using POST method slazerezals Linux - Server 3 02-22-2011 08:07 AM
[SOLVED] WGET webpage using POST method with multiple forms slazerezals Linux - General 3 02-21-2011 07:41 AM
[SOLVED] multiple slack boxes not posting to forms -- had to use winxp just to post this globaltree Slackware 6 10-09-2009 02:30 AM
mod_python - forms not working with publisher - Connection refused BrianK Linux - Software 1 10-16-2007 02:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration