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

Hello:

I have a form which a person completes. They hit the submit button and the script will open a page another page. This script is called camp.cgi. This form contains their name, number, etc.

On this new page, the person selects one of three options. If they select option 1 or 2, the script will do one routine - send an email. If they select option 3, the script will do a second routine. After the person selects their option, they will click submit and will go through a second script called camp1.cgi. It is camp1.cgi which will send the email or perform the second routine.

How do I pass all the data that was submitted via the first script (camp.cgi) to the second script (camp1.cgi)?

The email that will be sent via camp1.cgi needs to display all the information about the person which they completed on the first form which is processed via camp.cgi.

Any help would be greatly appreciated.

Thank you in advance.

Replies are listed 'Best First'.
Re: Passing form data between scripts
by shemp (Deacon) on Apr 01, 2005 at 00:26 UTC
    hidden form fields is one way.
      Hi,

      How do I accomplish using hidden form fields?

      Do I define the hidden fields in the first form which passes to the first script (camp.cgi)?

      Thanks for your help.
        In one page, inside a form, you can have a hidden field of the form <input type="hidden" name="thing" value="$thing"> and the script invoked by the form then gets the value by using param (using CGI.pm, of course), i.e. $thing=param('thing') You can use CGI.pm to produce the code for the hidden field using something like print hidden(-name=>"thing1",-value=>"thing2"); but I seem to recall having difficulty getting variables to interpolate in the value, so I've usually used the explicit first way. (If someone can comment on the interpolation problem, I'd be happy to hear about that...) The CGI module has built-in handling of "stickiness" (i.e. maintaining state (and I believe this makes use of hidden fields in a clever way... I don't understand it very well)) but it usually takes me such a lot of messing around to get it to work properly that I mostly just use hidden fields myself. That's not meant to detract from CGI.pm at all - it is a wonderful tool, I just don't know it well enough. (I always use CGI.pm, I just don't always use all of the subtleties available.)
        chas
Re: Passing form data between scripts
by Joost (Canon) on Apr 01, 2005 at 00:49 UTC
      Hi,

      Using the session link you gave me, I read about the CGI::Session.

      Can you tell me what I'm supposed to do with this line of code:
      my $session = new CGI::Session("driver:File", undef, {Directory=>'/tmp +'});


      I'm not sure what I'm supposed to do with it or how it's supposed to be used. Can you explain?

      Thank you.
        Here you create a new session object, and place the pointer to the object in $session.
        Anyway, better look here if you want to learn about sessions (that was one click away from the first page you entered :) )
        For your info, you need to store the session information on the webserver (either in a database, or on a file on the server). When you do another request and send your 'ticket' (session id), the server reads the proper session, and knows about your session data that is stored.

        "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
Re: Passing form data between scripts
by Popcorn Dave (Abbot) on Apr 01, 2005 at 04:54 UTC
    Something else you may want to consider is to make your script re-entrant using CGI.pm. It's similar to what Joost said.

    I'm doing that with a simple shopping cart application now. Since I didn't specify an action in my form, the application calls itself again when the submit button is pressed. I'm using this method to both check to make sure I have data in required fields, and to untaint it as well. The CGI docs have some good examples of this.

    HTH!

    Useless trivia: In the 2004 Las Vegas phone book there are approximately 28 pages of ads for massage, but almost 200 for lawyers.
Re: Passing form data between scripts
by TedPride (Priest) on Apr 01, 2005 at 07:56 UTC
    I'd use the same script for the whole process. Just include a flag at each step so you know which part to run:
    if (!$part) { # Print part 1, which includes: <input type="hidden" name="part" value="1"> } elsif ($part == 1) { # Process part 1 # Print part 2, which includes: <input type="hidden" name="part" value="2"> } elsif ($part == 2) { # Rinse and repeat as many times as necessary... }
    I wouldn't mess with sessions or database storage for something as simple as this.