Question on param()

Alan Stewart astewart at spawar.navy.mil
Tue Aug 8 16:55:46 CDT 2000


~sdpm~
On 7 Aug 00, at 13:25, Vasquez, Mike wrote:

>I have a newbie question.  Been learning the package for perl CGI.pm.
>
>I am trying to pass some parameters in the cgi script.
>
>As the attachment shows, 
>  if (param){ 
>     printform 
>  } else { 
>     processform 
>  }
>
>I can never get to the "processform" in the above if statement.
>
>One questions is do I have to parse the parameters that are passed in the
>form in order to get to the else statement.
>

I tried the following:

  ### test ###
  use CGI qw(:standard);

  $q = new CGI;

  PrintForm();

  sub PrintForm () {
      if ($q->param) {
          print "have params";
      }
      else {
          &ProcessForm;
      }
  }

  sub ProcessForm () {
      print "no params";
  }
  ### end test ###

and it works for me. I think the problem is a combination of logic and HTML. 
First, I assume that the first time you launch this, it is with a URL of 
modengr.pl with no query string ( ?blah=blah) and that should cause 
PrintForm to show you a list of all entries. The first execution receives no 
params and the code should be:

  sub PrintForm () {
      if ( ! param) {

Then when a link for one entry is clicked, that calls 
modengr.pl?fname=xxx&lname=yyy calling ProcessForm because there are 
params. ProcessForm needs to start out with:

  $fname=param('fname');
  $lname=param('lname');

Also, Processform has a form action=>?fname=xxx&lname=yyy&action=1.
The URL line fields of fname and lname are redundant with the form fields 
that will be passed by POST and the action field should be a form 
hiddenfield. When the submit is clicked, the script gets params again, 
action=1, but the code doesn't go that far:

  sub ProcessForm () {
     if (param('action') == 1) {ModifyDatabase()} else {

Don't forget that CGI.pm makes it possible to test this from the command 
line, without going thru a browser, at least as far as seeing which sub gets 
called. HOH.


---------------------------------------------------------------
Alan Stewart          )-[]-(           Electronics Engineer
Code D621           ~        ~         Network Operations
SPAWARSYSCEN       ~          ~  \     Satellite Communications
53560 Hull St   ( ~            ~  )    tel (619)524-3625
San Diego,CA  __|___             /|    fax (619)524-2607
92152-5001   ^\____/^^^^^^\    __| |_  astewart at spawar.navy.mil
------------^^^^^^^^^^^^^^^\__|______|_------------------------
~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.




More information about the San-Diego-pm mailing list