On Jan 17, 2008 3:56 PM, Xiong, Bob <[EMAIL PROTECTED]> wrote:
> Sure. Please see my code snippet below.
>
> use CGI ':standard';
>
> generate_form();
> do_work();
>
> sub generate_form {
> print start_form;
> print "ID# ", textfield('id');
> print submit('Action', 'OK');
> print end_form;
> }
>
> sub do_work {
> if (param('Action') eq 'OK') {
> # fetch record from database using id ...
> print "Phone number ", textfield('phone');
> } elsif (param('Action') eq 'Update') {
> my $new_phone_num = param('phone');
> # update database with newly acquired info ...
> }
> }
>
Bob,
Hi there. Sorry for the lag, moments after sending my last message I got
handed a task that kept me busy for the rest of the day.
Seems to me the problem is not checking the request type on entry. You
don't want to follow the same path for a POST as a GET.
Not entirely sure, since your snippet wasn't a complete stand alone chunk of
code. So, it took a little guesswork to fill in the missing bits. Anyhow,
I hacked up your last post and got something that works.
Mike
#!/usr/bin/perl
use warnings;
use strict;
use CGI ':standard';
print header('text/html'), start_html(-title=>'bob test');
print p("DEBUG: request method: $ENV{'REQUEST_METHOD'}");
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
generate_form();
} else {
do_work();
}
print end_html();
sub generate_form {
print start_form;
print "ID# ", textfield('id');
print submit('Action', 'OK');
print end_form;
}
sub do_work {
my @params = param();
print p("DEBUG: params => @params");
foreach my $p (param) {
my @v = param($p);
print p("DEBUG: param $p => (@v)");
}
if (param('Action') eq 'OK') {
# fetch record from database using id ...
print start_form();
print "Phone number ", textfield('phone');
print submit('Action', 'Update');
print end_form();
} elsif (param('Action') eq 'Update') {
my $new_phone_num = param('phone');
print p("DEBUG: phone => ($new_phone_num)");
print start_form();
print "Phone number ", textfield('phone');
print submit('Action', 'Verify');
print end_form();
} elsif (param('Action') eq 'Verify') {
print p("databse will be updated");
my $updated_number = param('phone');
print p("phone updated to $updated_number");
}
}
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm