Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

CGI Continue button

by neilwatson (Priest)
on Jul 16, 2002 at 18:13 UTC ( [id://182185]=perlquestion: print w/replies, xml ) Need Help??

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

I have an html form that has two text fields and two files to be uploaded. On submit the perl script formats the data and prints it to the browser for the user to verify. While still keeping all the scalars I've contructed in the script, is it possible to have a "continue" botton sent to the browser? When the button is pressed by the user, the script finishes by doing final processing of the original data and redirecting the browser when finished.

Can this be done?

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re: CGI Continue button
by erikharrison (Deacon) on Jul 16, 2002 at 18:42 UTC

    In essence, what you is a state problem. HTTP is a stateless protocol, which means that no transaction remembers anything about the prior transaction. However, there are a couple of ways to "fake" state retention in a CGI script.

    1. When your user submits this data, you have the files saved to temp files and the text fields in to scalars ($foo and $baz). Untaint $foo and $baz, slap them in a database. Add the names of the temp files to this database. In the second HTML page (which fuzzyping rightly directs to CGI::Application to handle) plant a hidden form field with the key to those database entries. Have a submit button with a "continue" value, and if the script recieves a continue vale it checks the hidden parameter for the database key, and pulls out all the right info to do appropriate things with. If not, it redirects to the correct page, and deletes the entry in the database and the temp files.
    2. Doing the above but using cookies to maintain state.
    3. Since you are presenting the user with formatted data, embed that formatted data into a hidden form field on the page, and have a submit button with a "continue" value. If the script recieves the "continue" value, it checks the hidden param for the preformatted data and does appropriate things.
    4. I'd go with #1. It's a little more work than #3 but is cleaner, scales better, and is more readily extensible. #2 is really just there for completeness, as cookies are a bad fit for this problem UNLESS this is a largeish website with a user logon already in place. If this is the case, then the user already has a cookie, and you can leverage that for state maintenance.

      Cheers,
      Erik

      Light a man a fire, he's warm for a day. Catch a man on fire, and he's warm for the rest of his life. - Terry Pratchet

Re: CGI Continue button
by fuzzyping (Chaplain) on Jul 16, 2002 at 18:27 UTC
    I'm not quite sure what you're trying to present to the user in the interim, but there's no reason why you can't simply include another SUBMIT button, albeit with VALUE="Continue". Assuming you're keeping track of your user session via cookies or hidden values, this should fulfill your requirements (although I'm not entirely clear on them). You might want to look at CGI::Application to help handle your "run-modes".

    Something else that might help you out is this technique from Merlyn.

    HTH!

    -fp

    Update: s/shouldn\'t/should/
Re: CGI Continue button
by Cine (Friar) on Jul 16, 2002 at 22:46 UTC
    What you are trying to do wont work because as stated above the HTTP protocol is stateless. But what is actually you problem is this particular case is that most browsers will timeout eventually, and that is usually before the user makes up their mind about what to do.

    Therefore you need to have your state information embedded in the next request (this gives a lot of problems securitywise, but that is a whole other matter). And this also means that you have to cut up your processing into two segments, one where the user gives you the data and one where she/he verifies it.

    T I M T O W T D I

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://182185]
Approved by Rex(Wrecks)
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-25 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found