Trihedralguy has asked for the wisdom of the Perl Monks concerning the following question:

Im using Param() twice in my program (two different .cgi scripts), but I cant figure out how to get perl to know that. Basically my first page uses a form an a
Unless(Param()) { Show Form } else { Process form and do some other link related stuff. }

Then from there the users needs to click links which are created by my script to have the value of ID sent from page 1 to page 2. So this link here will tell page to do "id=2" stuff on page 2: myscript.com/secondpage.cgi?id=2..But page two also uses unless(param()) to get the users input, etc etc...But since I guess they are both using param when you do the URL above it automatically gives a "results" page as if you submitted the 2nd form? Very strange, do I need to declare Param differently, I cant figure this thing out.

Replies are listed 'Best First'.
Re: Quick Param Question
by f00li5h (Chaplain) on Mar 29, 2007 at 00:01 UTC

    You may be interested in CGI::FormBuilder the docs have an example that goes a little something like this

    # snipped creation of form object if ($form->submitted && $form->validate) { # Get form fields as hashref my $field = $form->fields; # Do something to update your data (you would write this) do_data_update($field->{lname}, $field->{fname}, $field->{email}, $field->{phone}, $field->{gender}); # Show confirmation screen print $form->confirm(header => 1); } else { # Print out the form print $form->render(header => 1); }

    Update Here the form's validation rules will prevent the one id parmeter from having your code believe that the form has been submitted

    @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;
Re: Quick Param Question
by rodion (Chaplain) on Mar 29, 2007 at 02:13 UTC
    Try
    unless (param('submit'))
    to detect if perl was invoked from a form. (If you've used submit(-name=>'somename'),then substitute "somename" for "submit".)

    When you just check to see if param() returns false, you're checking that there were no parameters, but when you specify "id=2" in a link, you do have a parameter. Checking for a parameter named "submit" checks if the "submit" button was clicked (or the user pressed enter), which is what lests you know the other parameters were set by the form, not a link.

      rodion, why not check all the form components automatically with a nice library, rather than checking for a single parameter to make it all work?

      Checking param( submit ) doesn't work well, particularly for complex, multi-stage forms, or forms with more than one operation, like:

      email:_______________
      [subscribe] [unsubscribe]

      or something wth a

      [<< back ][forward >> ]
      wizzard style interaction model.

      @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;
        It's worth pointing the questioner in a better direction, and it's also worthwhile explaining the problem he's run into where he is.

        Your advice is good, I agree with it, and the OP will do well to look further in the direction of CGI::FormBuilder, as you suggested in the first post.

        My take on the OP's question was that he was somewhat new to forms and parameters, was working from the example givin in the CGI module, and was a bit puzzled by the code from that example not working for him. My aim was to help him understand what was going on a little better, in answer to the "I cant figure this thing out." plea at the end of his post.