Passing Variables from One Perlscript to Another

Discussion in 'Perl Misc' started by Joe, Sep 30, 2003.

  1. Joe

    Joe Guest

    I am trying to write a Perlscript to be used with some HTML pages. Here is
    how it works:



    1.. The first HTML page has a form which requests for user input. Then it
    passes the QUERY_STRING to a Perl script.
    2.. The Perl script will then validate the data. If input validation
    fails, it returns to the previous screen and asks the user to retry. If the
    validation passes, it display the user input and asks for confirmation.
    3.. If the user chooses okay to proceed, it will pass the validated data
    to another Perl script to execute some queries from a database.


    I can manage to go from step 1 to step 2. But I don't know how to pass the
    variables from one Perl script to another. I am not sure if I should use
    the POST or GET method. I think there should be some better ways.
     
    Joe, Sep 30, 2003
    #1
    1. Advertising

  2. "Joe" <> wrote in message
    news:fkneb.2344$...
    > I am trying to write a Perlscript to be used with some HTML pages. Here

    is
    > how it works:
    >
    >
    >
    > 1.. The first HTML page has a form which requests for user input. Then

    it
    > passes the QUERY_STRING to a Perl script.
    > 2.. The Perl script will then validate the data. If input validation
    > fails, it returns to the previous screen and asks the user to retry. If

    the
    > validation passes, it display the user input and asks for confirmation.
    > 3.. If the user chooses okay to proceed, it will pass the validated data
    > to another Perl script to execute some queries from a database.
    >
    >
    > I can manage to go from step 1 to step 2. But I don't know how to pass

    the
    > variables from one Perl script to another.


    Once the data has been validated, couldn't it be stored in a temporary file
    on your server? The second Perl script could then access the file and use
    its contents. (There are probably more elegant/secure solutions, but this
    may get you started.)

    jimk
     
    James E Keenan, Sep 30, 2003
    #2
    1. Advertising

  3. In article <fkneb.2344$>,
    "Joe" <> wrote:

    > I am trying to write a Perlscript to be used with some HTML pages. Here is
    > how it works:
    >
    >
    >
    > 1.. The first HTML page has a form which requests for user input. Then it
    > passes the QUERY_STRING to a Perl script.
    > 2.. The Perl script will then validate the data. If input validation
    > fails, it returns to the previous screen and asks the user to retry. If the
    > validation passes, it display the user input and asks for confirmation.
    > 3.. If the user chooses okay to proceed, it will pass the validated data
    > to another Perl script to execute some queries from a database.
    >
    >
    > I can manage to go from step 1 to step 2. But I don't know how to pass the
    > variables from one Perl script to another. I am not sure if I should use
    > the POST or GET method. I think there should be some better ways.
    >


    i normally use one script to do it all.

    in the script, if the form has been submitted, the script validates the
    input data. if the data is valid, final processing occurs (db
    activities, emails sent, etc.), whatever thank you page is shown, then
    the script exits. if the data is not valid, the script "falls thru" to a
    section where the input form is displayed, populated with input data, if
    any. note that both the input form and the thank you pages are usually
    external template files.

    i'm pretty sure there are also perl modules out there that do the same
    basic thing. anybody?

    hth-

    --
    Michael Budash
     
    Michael Budash, Sep 30, 2003
    #3
  4. Joe

    Eric Bohlman Guest

    "Joe" <> wrote in
    news:fkneb.2344$:

    > I am trying to write a Perlscript to be used with some HTML pages.
    > Here is how it works:
    >
    > 1.. The first HTML page has a form which requests for user input.
    > Then it
    > passes the QUERY_STRING to a Perl script.
    > 2.. The Perl script will then validate the data. If input
    > validation
    > fails, it returns to the previous screen and asks the user to retry.
    > If the validation passes, it display the user input and asks for
    > confirmation.
    > 3.. If the user chooses okay to proceed, it will pass the validated
    > data
    > to another Perl script to execute some queries from a database.
    >
    > I can manage to go from step 1 to step 2. But I don't know how to
    > pass the variables from one Perl script to another. I am not sure if
    > I should use the POST or GET method. I think there should be some
    > better ways.


    Read the documentation for CGI.pm, paying particular attention to the parts
    about "sticky" form values. CGI.pm should contain everything you need to
    do what you want.
     
    Eric Bohlman, Oct 1, 2003
    #4
  5. Joe

    Joe Guest


    > >

    >
    > i normally use one script to do it all.
    >
    > in the script, if the form has been submitted, the script validates the
    > input data. if the data is valid, final processing occurs (db
    > activities, emails sent, etc.), whatever thank you page is shown, then
    > the script exits. if the data is not valid, the script "falls thru" to a
    > section where the input form is displayed, populated with input data, if
    > any. note that both the input form and the thank you pages are usually
    > external template files.
    >


    I can live with just one script. But what I want to do is to display the
    validated input and ask for confirmation before proceeding with the long
    data extraction process. I don't know how to get user input in the middle
    of a script.

    Joe
     
    Joe, Oct 1, 2003
    #5
  6. In article
    <kvreb.173431$>,
    "Joe" <> wrote:

    > > >

    > >
    > > i normally use one script to do it all.
    > >
    > > in the script, if the form has been submitted, the script validates the
    > > input data. if the data is valid, final processing occurs (db
    > > activities, emails sent, etc.), whatever thank you page is shown, then
    > > the script exits. if the data is not valid, the script "falls thru" to a
    > > section where the input form is displayed, populated with input data, if
    > > any. note that both the input form and the thank you pages are usually
    > > external template files.
    > >

    >
    > I can live with just one script. But what I want to do is to display the
    > validated input and ask for confirmation before proceeding with the long
    > data extraction process. I don't know how to get user input in the middle
    > of a script.


    if {formsubmitbutton) {
    validatedata(); # may set error
    unless (error) {
    showconfirmpage(); # hidden fields hold input data
    exit;
    }
    }

    if (confirmbutton) {
    dodataextraction(); # use data from hidden fields
    exit;
    }

    # if we get this far:
    showinputform(); # populate with input data, if any; show error, if any

    --
    Michael Budash
     
    Michael Budash, Oct 1, 2003
    #6
  7. Joe

    Trent Curry Guest

    Joe wrote:
    >> i normally use one script to do it all.
    >>
    >> in the script, if the form has been submitted, the script validates
    >> the input data. if the data is valid, final processing occurs (db
    >> activities, emails sent, etc.), whatever thank you page is shown,
    >> then the script exits. if the data is not valid, the script "falls
    >> thru" to a section where the input form is displayed, populated with
    >> input data, if any. note that both the input form and the thank you
    >> pages are usually external template files.
    >>

    >
    > I can live with just one script. But what I want to do is to display
    > the validated input and ask for confirmation before proceeding with
    > the long data extraction process. I don't know how to get user input
    > in the middle of a script.
    >
    > Joe


    What you could do is,

    1) First write the input to a confirmation page in the form on hidden
    fields, then when that is submitted, then process the data, or

    2) First write the input to a temp file (MD5.pm is a good way to
    generate random files names; I would suggest File::Temp for temp
    files, but afaik the file would be deleted by the time the script
    exits.) After you have a temp file written, send a confirmation
    page, and include the name of the temp file, which is being used
    sort of as a session id, so when the user sends the confirmation,
    it gets the file name from the hidden input field containing it
    and then process as necessary.

    Hope this is of some use.

    --
    Trent Curry

    perl -e
    '($s=qq/e29716770256864702379602c6275605/)=~s!([0-9a-f]{2})!pack("h2",$1)!eg
    ;print(reverse("$s")."\n");'
     
    Trent Curry, Oct 1, 2003
    #7
  8. >Subject: Passing Variables from One Perlscript to Another
    >Date: Tue, 30 Sep 2003 18:16:20 -0400
    >
    >I am trying to write a Perlscript to be used with some HTML pages. Here is
    >how it works:
    >
    >
    >
    > 1.. The first HTML page has a form which requests for user input. Then it
    >passes the QUERY_STRING to a Perl script.
    > 2.. The Perl script will then validate the data. If input validation
    >fails, it returns to the previous screen and asks the user to retry. If the
    >validation passes, it display the user input and asks for confirmation.
    > 3.. If the user chooses okay to proceed, it will pass the validated data
    >to another Perl script to execute some queries from a database.
    >
    >
    >I can manage to go from step 1 to step 2. But I don't know how to pass the
    >variables from one Perl script to another. I am not sure if I should use
    >the POST or GET method. I think there should be some better ways.
    >


    I use a set number of fields for all data I need to persist. The fields are
    hidden except on the page which prompts for that specific data. One page may
    prompt name and ID so those fields are not hidden on that page. Another page
    may prompt for date so that field is not hidden on that page. All scripts
    include a module which gets environment info and makes sure needed hash
    values are not undef.
     
    David McDivitt, Oct 1, 2003
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe
    Replies:
    1
    Views:
    1,187
    Jim Gibson
    Oct 1, 2003
  2. Steve C. Orr, MCSD
    Replies:
    0
    Views:
    507
    Steve C. Orr, MCSD
    Aug 8, 2003
  3. Prakash R.
    Replies:
    1
    Views:
    311
    Child
    Aug 8, 2003
  4. Robert Cohen
    Replies:
    3
    Views:
    311
    Andrew Durstewitz
    Jul 15, 2003
  5. Guest
    Replies:
    6
    Views:
    154
    Joe Smith
    Jul 25, 2004
Loading...

Share This Page