Hi Mike, Thanks for the investigation. I tested your flow and it worked in a way. I had to save away the id in a file in order to access it in the Update or Verify block. I had to use the id to update the record in the database.
Thanks for your time, appreciated. Bob -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Mike Williams Sent: Friday, January 18, 2008 3:12 PM To: [email protected] Subject: Re: [Boston.pm] cgi form question 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 The information transmitted in this electronic communication is intended only for the person or entity to whom it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this information in error, please contact the Compliance HelpLine at 800-856-1983 and properly dispose of this information. _______________________________________________ Boston-pm mailing list [email protected] http://mail.pm.org/mailman/listinfo/boston-pm

